aaa
Dominic Gannaway 8 months ago
parent 4b851c8351
commit 9cbc4aaea4

@ -272,7 +272,7 @@ export function trigger_async_boundary(effect, trigger) {
/** /**
* @template T * @template T
* @param {() => Promise<T> | Promise<T>} input * @param {(() => Promise<T>) | Promise<T>} input
* @returns {Promise<{ exit: () => T }>} * @returns {Promise<{ exit: () => T }>}
*/ */
export async function suspend(input) { export async function suspend(input) {

@ -18,12 +18,11 @@ import {
update_reaction, update_reaction,
increment_write_version, increment_write_version,
set_active_effect, set_active_effect,
component_context, component_context
get
} from '../runtime.js'; } from '../runtime.js';
import { equals, safe_equals } from './equality.js'; import { equals, safe_equals } from './equality.js';
import * as e from '../errors.js'; import * as e from '../errors.js';
import { destroy_effect, render_effect } from './effects.js'; import { block, destroy_effect } from './effects.js';
import { inspect_effects, internal_set, set_inspect_effects, source } from './sources.js'; import { inspect_effects, internal_set, set_inspect_effects, source } from './sources.js';
import { get_stack } from '../dev/tracing.js'; import { get_stack } from '../dev/tracing.js';
import { tracing_mode_flag } from '../../flags/index.js'; import { tracing_mode_flag } from '../../flags/index.js';
@ -88,10 +87,10 @@ export function async_derived(fn) {
throw new Error('TODO cannot create unowned async derived'); throw new Error('TODO cannot create unowned async derived');
} }
let promise = /** @type {Promise<V>} */ (/** @type {unknown} */ (undefined)); var promise = /** @type {Promise<V>} */ (/** @type {unknown} */ (undefined));
let value = source(/** @type {V} */ (undefined)); var value = source(/** @type {V} */ (undefined));
render_effect(() => { block(() => {
const current = (promise = fn()); const current = (promise = fn());
suspend(promise).then((v) => { suspend(promise).then((v) => {
@ -104,7 +103,7 @@ export function async_derived(fn) {
}); });
// TODO what happens when the promise rejects? // TODO what happens when the promise rejects?
}); }, EFFECT_HAS_DERIVED);
return promise.then(() => value); return promise.then(() => value);
} }

Loading…
Cancel
Save