experiment-s2
Dominic Gannaway 8 hours ago
parent be95b34f29
commit 6979d476e5

@ -1,7 +1,7 @@
/** @import { Effect, Source, TemplateNode, } from '#client' */
import { UNINITIALIZED } from '../../../../constants.js';
import { AWAIT_EFFECT, BOUNDARY_EFFECT, EFFECT_TRANSPARENT, PENDING } from '../../constants.js';
import { AWAIT_EFFECT, BOUNDARY_EFFECT, EFFECT_TRANSPARENT, INERT, PENDING } from '../../constants.js';
import { derived } from '../../reactivity/deriveds.js';
import {
block,
@ -254,8 +254,11 @@ export function trigger_async_boundary(effect, trigger) {
*/
export function await_derived(fn) {
var current = active_effect;
/** @type {Source<V | typeof PENDING>} */
var value = source(PENDING);
/** @type {Source<V | typeof UNINITIALIZED>} */
var value = source(UNINITIALIZED);
// We mark the source signal as inert as it's value
// can throw if in an async pending state
value.f ^= INERT;
/** @type {Promise<V> | typeof UNINITIALIZED} */
var previous_promise = UNINITIALIZED;
var derived_promise = derived(fn);
@ -276,9 +279,6 @@ export function await_derived(fn) {
if (should_suspend) {
set_is_within_await(true);
untrack(() => {
set(value, PENDING);
});
trigger_async_boundary(current, ASYNC_INCREMENT);
// If we're updating, then we need to flush the boundary microtasks
@ -287,6 +287,9 @@ export function await_derived(fn) {
}
promise.then((v) => {
if (previous_promise !== promise) {
return;
}
set(value, v);
trigger_async_boundary(current, ASYNC_DECREMENT);
});

@ -1035,7 +1035,10 @@ export function get(signal) {
value = signal.v;
if (value === PENDING) {
if (
(flags & INERT) !== 0 &&
(is_within_await || (active_effect !== null && (active_effect.f & INERT) !== 0))
) {
throw PENDING;
}

Loading…
Cancel
Save