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(); var restore = capture();
Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => { let boundary = effect.b;
restore();
fn(node, ...result); 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();
// TODO is this necessary? Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => {
batch.run(() => { batch.run(() => {
restore();
fn(node, ...result);
// TODO is this necessary?
schedule_effect(effect); schedule_effect(effect);
}); });
boundary.decrement();
}); });
} }

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

Loading…
Cancel
Save