pull/18062/merge
Rich Harris 4 months ago
parent ef44fbe189
commit 494f06aad1

@ -38,8 +38,22 @@ export function flatten(blockers, sync, async, fn) {
// Filter out already-settled blockers - no need to wait for them
var pending = blockers.filter((b) => !b.settled);
var deriveds = sync.map(d);
if (DEV) {
deriveds.forEach((d, i) => {
// TODO this is kinda useful for debugging but a lousy implementation —
// maybe the compiler could pass through the template string
d.label = sync[i]
.toString()
.replace('() => ', '')
.replaceAll('$.eager(() => ', '$state.eager(')
.replace(/\$\.get\((.+?)\)/g, (_, id) => id);
});
}
if (async.length === 0 && pending.length === 0) {
fn(sync.map(d));
fn(deriveds);
return;
}
@ -54,14 +68,13 @@ export function flatten(blockers, sync, async, fn) {
: null;
/**
* @param {Array<() => any>} sync
* @param {Source[]} async
*/
function finish(sync, async) {
function finish(async) {
restore();
try {
fn([...sync.map(d), ...async]);
fn([...deriveds, ...async]);
} catch (error) {
if ((parent.f & DESTROYED) === 0) {
invoke_error_boundary(error, parent);
@ -73,7 +86,7 @@ export function flatten(blockers, sync, async, fn) {
// Fast path: blockers but no async expressions
if (async.length === 0) {
/** @type {Promise<any>} */ (blocker_promise).then(() => finish(sync, []));
/** @type {Promise<any>} */ (blocker_promise).then(() => finish([]));
return;
}
@ -82,7 +95,7 @@ export function flatten(blockers, sync, async, fn) {
// Full path: has async expressions
function run() {
Promise.all(async.map((expression) => async_derived(expression)))
.then((result) => finish(sync, result))
.then(finish)
.catch((error) => invoke_error_boundary(error, parent))
.finally(() => decrement_pending());
}

Loading…
Cancel
Save