pull/15844/head
Rich Harris 2 months ago
parent a7e0c84782
commit 8f47fa8119

@ -17,35 +17,35 @@ import { async_derived, derived, derived_safe_equal } from './deriveds.js';
export function flatten(sync, async, fn) { export function flatten(sync, async, fn) {
const d = is_runes() ? derived : derived_safe_equal; const d = is_runes() ? derived : derived_safe_equal;
if (async.length > 0) { if (async.length === 0) {
var batch = current_batch; fn(sync.map(d));
var parent = /** @type {Effect} */ (active_effect); return;
}
var restore = capture(); var batch = current_batch;
var parent = /** @type {Effect} */ (active_effect);
var boundary = get_pending_boundary(); var restore = capture();
var boundary = get_pending_boundary();
Promise.all(async.map((expression) => async_derived(expression))) Promise.all(async.map((expression) => async_derived(expression)))
.then((result) => { .then((result) => {
batch?.activate(); batch?.activate();
restore(); restore();
try { try {
fn([...sync.map(d), ...result]); fn([...sync.map(d), ...result]);
} catch (error) { } catch (error) {
// ignore errors in blocks that have already been destroyed // ignore errors in blocks that have already been destroyed
if ((parent.f & DESTROYED) === 0) { if ((parent.f & DESTROYED) === 0) {
invoke_error_boundary(error, parent); invoke_error_boundary(error, parent);
}
} }
}
batch?.deactivate(); batch?.deactivate();
}) })
.catch((error) => { .catch((error) => {
boundary.error(error); boundary.error(error);
}); });
} else {
fn(sync.map(d));
}
} }

Loading…
Cancel
Save