pull/15844/head
Rich Harris 3 months ago
parent 3f3734b3fc
commit ee3a02aa50

@ -6,7 +6,6 @@ import {
CLEAN,
DERIVED,
DIRTY,
EFFECT_ASYNC,
EFFECT_PRESERVED,
MAYBE_DIRTY,
STALE_REACTION,
@ -26,7 +25,7 @@ import {
import { equals, safe_equals } from './equality.js';
import * as e from '../errors.js';
import * as w from '../warnings.js';
import { destroy_effect, render_effect } from './effects.js';
import { async_effect, destroy_effect, render_effect } from './effects.js';
import { inspect_effects, internal_set, set_inspect_effects, source } from './sources.js';
import { get_stack } from '../dev/tracing.js';
import { tracing_mode_flag } from '../../flags/index.js';
@ -114,7 +113,7 @@ export function async_derived(fn, location) {
// only suspend in async deriveds created on initialisation
var should_suspend = !active_reaction;
render_effect(() => {
async_effect(() => {
if (DEV) current_async_effect = active_effect;
try {
@ -187,7 +186,7 @@ export function async_derived(fn, location) {
};
promise.then(handler, (e) => handler(null, e || 'unknown'));
}, EFFECT_ASYNC | EFFECT_PRESERVED);
});
return new Promise((fulfil) => {
/** @param {Promise<V>} p */

@ -33,7 +33,8 @@ import {
EFFECT_PRESERVED,
BOUNDARY_EFFECT,
STALE_REACTION,
USER_EFFECT
USER_EFFECT,
EFFECT_ASYNC
} from '#client/constants';
import * as e from '../errors.js';
import { DEV } from 'esm-env';
@ -331,6 +332,14 @@ export function legacy_pre_effect_reset() {
});
}
/**
* @param {() => void | (() => void)} fn
* @returns {Effect}
*/
export function async_effect(fn) {
return create_effect(EFFECT_ASYNC | EFFECT_PRESERVED, fn, true);
}
/**
* @param {() => void | (() => void)} fn
* @returns {Effect}

Loading…
Cancel
Save