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

@ -6,7 +6,6 @@ import {
CLEAN, CLEAN,
DERIVED, DERIVED,
DIRTY, DIRTY,
EFFECT_ASYNC,
EFFECT_PRESERVED, EFFECT_PRESERVED,
MAYBE_DIRTY, MAYBE_DIRTY,
STALE_REACTION, STALE_REACTION,
@ -26,7 +25,7 @@ import {
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 * as w from '../warnings.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 { 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';
@ -114,7 +113,7 @@ export function async_derived(fn, location) {
// 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(() => { async_effect(() => {
if (DEV) current_async_effect = active_effect; if (DEV) current_async_effect = active_effect;
try { try {
@ -187,7 +186,7 @@ export function async_derived(fn, location) {
}; };
promise.then(handler, (e) => handler(null, e || 'unknown')); promise.then(handler, (e) => handler(null, e || 'unknown'));
}, EFFECT_ASYNC | EFFECT_PRESERVED); });
return new Promise((fulfil) => { return new Promise((fulfil) => {
/** @param {Promise<V>} p */ /** @param {Promise<V>} p */

@ -33,7 +33,8 @@ import {
EFFECT_PRESERVED, EFFECT_PRESERVED,
BOUNDARY_EFFECT, BOUNDARY_EFFECT,
STALE_REACTION, STALE_REACTION,
USER_EFFECT USER_EFFECT,
EFFECT_ASYNC
} from '#client/constants'; } from '#client/constants';
import * as e from '../errors.js'; import * as e from '../errors.js';
import { DEV } from 'esm-env'; 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 * @param {() => void | (() => void)} fn
* @returns {Effect} * @returns {Effect}

Loading…
Cancel
Save