enforce linear order

pull/16197/head
Rich Harris 5 months ago
parent 13a9b70f78
commit 1dd383ea54

@ -106,14 +106,27 @@ export function async_derived(fn, location) {
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));
/** @type {Promise<V> | null} */
var prev = null;
// 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;
render_effect(() => { render_effect(() => {
if (DEV) from_async_derived = active_effect; if (DEV) from_async_derived = active_effect;
promise = Promise.resolve(fn()); var p = fn();
if (DEV) from_async_derived = null; if (DEV) from_async_derived = null;
promise =
prev === null
? Promise.resolve(p)
: prev.then(
() => p,
() => p
);
prev = promise;
var restore = capture(); var restore = capture();
var batch = /** @type {Batch} */ (current_batch); var batch = /** @type {Batch} */ (current_batch);
@ -129,6 +142,8 @@ export function async_derived(fn, location) {
promise.then( promise.then(
(v) => { (v) => {
prev = null;
if ((parent.f & DESTROYED) !== 0) { if ((parent.f & DESTROYED) !== 0) {
return; return;
} }
@ -160,6 +175,8 @@ export function async_derived(fn, location) {
} }
}, },
(e) => { (e) => {
prev = null;
handle_error(e, parent, null, parent.ctx); handle_error(e, parent, null, parent.ctx);
} }
); );

@ -34,6 +34,7 @@ export default test({
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await Promise.resolve();
await tick(); await tick();
assert.htmlEqual(target.innerHTML, '<p>hello</p>'); assert.htmlEqual(target.innerHTML, '<p>hello</p>');

Loading…
Cancel
Save