|
|
@ -89,7 +89,7 @@ export function derived(fn) {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @template V
|
|
|
|
* @template V
|
|
|
|
* @param {() => Promise<V>} fn
|
|
|
|
* @param {() => V | Promise<V>} fn
|
|
|
|
* @param {string} [location] If provided, print a warning if the value is not read immediately after update
|
|
|
|
* @param {string} [location] If provided, print a warning if the value is not read immediately after update
|
|
|
|
* @returns {Promise<Source<V>>}
|
|
|
|
* @returns {Promise<Source<V>>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -173,12 +173,21 @@ export function async_derived(fn, location) {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}, EFFECT_ASYNC | EFFECT_PRESERVED);
|
|
|
|
}, EFFECT_ASYNC | EFFECT_PRESERVED);
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise(async (fulfil) => {
|
|
|
|
return new Promise((fulfil) => {
|
|
|
|
// if the effect re-runs before the initial promise
|
|
|
|
/** @param {Promise<V>} p */
|
|
|
|
// resolves, delay resolution until we have a value
|
|
|
|
function next(p) {
|
|
|
|
var p;
|
|
|
|
p.then(() => {
|
|
|
|
while (p !== (p = promise)) await p;
|
|
|
|
if (p === promise) {
|
|
|
|
fulfil(signal);
|
|
|
|
fulfil(signal);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// if the effect re-runs before the initial promise
|
|
|
|
|
|
|
|
// resolves, delay resolution until we have a value
|
|
|
|
|
|
|
|
next(promise);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next(promise);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|