pull/16197/head
Rich Harris 5 months ago
parent fc18e26bdd
commit ed172125b2

@ -18,13 +18,27 @@ export function async(node, expressions, fn) {
var restore = capture();
let boundary = effect.b;
while (boundary !== null && !boundary.has_pending_snippet()) {
boundary = boundary.parent;
}
if (boundary === null) {
throw new Error('TODO cannot create async derived outside a boundary with a pending snippet');
}
boundary.increment();
Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => {
batch.run(() => {
restore();
fn(node, ...result);
// TODO is this necessary?
batch.run(() => {
schedule_effect(effect);
});
boundary.decrement();
});
}

@ -119,10 +119,13 @@ export class Boundary {
return branch(() => this.#children(this.#anchor));
});
if (this.#pending_count === 0) {
if (this.#pending_count > 0) {
this.#show_pending_snippet();
} else {
pause_effect(/** @type {Effect} */ (this.#pending_effect), () => {
this.#pending_effect = null;
});
this.ran = true;
}
});
} else {
@ -130,14 +133,14 @@ export class Boundary {
if (this.#pending_count > 0) {
this.#show_pending_snippet();
} else {
this.ran = true;
}
}
reset_is_throwing_error();
}, flags);
this.ran = true;
if (hydrating) {
this.#anchor = hydrate_node;
}
@ -189,6 +192,8 @@ export class Boundary {
}
commit() {
this.ran = true;
if (this.#pending_effect) {
pause_effect(this.#pending_effect, () => {
this.#pending_effect = null;
@ -242,10 +247,10 @@ export class Boundary {
}
});
this.ran = true;
if (this.#pending_count > 0) {
this.#show_pending_snippet();
} else {
this.ran = true;
}
};

Loading…
Cancel
Save