pull/15844/head
Rich Harris 2 months ago
parent 12188f37f6
commit 4d8432a0f2

@ -14,10 +14,13 @@ export function async(node, expressions, fn) {
boundary.update_pending_count(1);
flatten([], expressions, (values) => {
// get values eagerly to avoid creating blocks if they reject
for (const d of values) get(d);
try {
// get values eagerly to avoid creating blocks if they reject
for (const d of values) get(d);
fn(node, ...values);
boundary.update_pending_count(-1);
fn(node, ...values);
} finally {
boundary.update_pending_count(-1);
}
});
}

@ -27,8 +27,6 @@ export function flatten(sync, async, fn) {
Promise.all(async.map((expression) => async_derived(expression)))
.then((result) => {
if ((parent.f & DESTROYED) !== 0) return;
batch?.activate();
restore();
@ -36,7 +34,10 @@ export function flatten(sync, async, fn) {
try {
fn([...sync.map(d), ...result]);
} catch (error) {
invoke_error_boundary(error, parent);
// ignore errors in blocks that have already been destroyed
if ((parent.f & DESTROYED) === 0) {
invoke_error_boundary(error, parent);
}
}
batch?.deactivate();

@ -2,23 +2,24 @@ import { tick } from 'svelte';
import { test } from '../../test';
export default test({
async test({ assert, target }) {
const [increment, shift] = target.querySelectorAll('button');
async test({ assert, target, errors }) {
const [increment, resolve, reject] = target.querySelectorAll('button');
increment.click();
await tick();
shift.click();
reject.click();
await tick();
shift.click();
resolve.click();
await tick();
assert.htmlEqual(
target.innerHTML,
`
<button>increment</button>
<button>shift</button>
<button>resolve</button>
<button>reject</button>
<p>false</p>
<p>1</p>
`

Loading…
Cancel
Save