Skip to content

Commit

Permalink
fix async digest race condition, [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyraspopov committed Aug 9, 2024
1 parent 072a449 commit f2453ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions inertial.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function ObservableScope(schedule = (cb) => cb()) {
marking = [head];
fn();
schedule = temp;
if (marking.length > 0) schedule(digest);
schedule(digest);
}

function deref(...signals) {
Expand All @@ -162,7 +162,7 @@ export function ObservableScope(schedule = (cb) => cb()) {

function dispose() {
let cursor = head;
while ((cursor = cursor.next) !== tail) {
while (cursor != null && (cursor = cursor.next) !== tail) {
if (cursor.flag & DISPOSER) cursor.dispose();
}
head = { prev: null, next: null };
Expand All @@ -173,8 +173,11 @@ export function ObservableScope(schedule = (cb) => cb()) {
function digest() {
flushing = true;
let cursor = marking[0];
while ((cursor = cursor.next) !== tail) {
if (cursor.flag & CONSUMER && marking.some((node) => cursor.tracking.has(node))) {
while (cursor != null && (cursor = cursor.next) !== tail) {
if (
cursor.flag & CONSUMER &&
marking.some((node) => cursor.tracking.has(node))
) {
cursor.update();
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inertial",
"version": "0.2.1",
"version": "0.2.2",
"type": "module",
"description": "A tiny library for integrating reactive signals anywhere.",
"author": "Oleksii Raspopov",
Expand Down

0 comments on commit f2453ae

Please sign in to comment.