pull/16197/head
Rich Harris 6 months ago
parent a840f00b67
commit 3fe77cdebe

@ -100,18 +100,22 @@ export function async_derived(fn, location) {
throw new Error('TODO cannot create unowned async derived'); throw new Error('TODO cannot create unowned async derived');
} }
let boundary = parent.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');
}
var promise = /** @type {Promise<V>} */ (/** @type {unknown} */ (undefined)); var promise = /** @type {Promise<V>} */ (/** @type {unknown} */ (undefined));
var signal = source(/** @type {V} */ (UNINITIALIZED)); var signal = source(/** @type {V} */ (UNINITIALIZED));
// only suspend in async deriveds created on initialisation // only suspend in async deriveds created on initialisation
var should_suspend = !active_reaction; var should_suspend = !active_reaction;
var boundary = /** @type {Effect} */ parent.b;
while (boundary !== null && !boundary.has_pending_snippet()) {
boundary = boundary.parent;
}
render_effect(() => { render_effect(() => {
if (DEV) from_async_derived = active_effect; if (DEV) from_async_derived = active_effect;
promise = fn(); promise = fn();
@ -125,10 +129,6 @@ export function async_derived(fn, location) {
if (fork !== null) { if (fork !== null) {
fork.increment(); fork.increment();
} else { } else {
if (boundary === null) {
throw new Error('TODO');
}
// if nearest pending boundary is not ready, attach to the boundary // if nearest pending boundary is not ready, attach to the boundary
boundary.increment(); boundary.increment();
} }
@ -147,10 +147,6 @@ export function async_derived(fn, location) {
if (fork !== null) { if (fork !== null) {
fork.decrement(); fork.decrement();
} else { } else {
if (boundary === null) {
throw new Error('TODO');
}
boundary.decrement(); boundary.decrement();
} }
} }

Loading…
Cancel
Save