make batch.#deferred private

pull/15844/head
Rich Harris 3 months ago
parent 3156a24161
commit 5fda0113b9

@ -1,5 +1,6 @@
/** @import { Derived, Effect, Source } from '#client' */ /** @import { Derived, Effect, Source } from '#client' */
import { CLEAN, DIRTY } from '#client/constants'; import { CLEAN, DIRTY } from '#client/constants';
import { deferred } from '../../shared/utils.js';
import { import {
flush_queued_effects, flush_queued_effects,
flush_queued_root_effects, flush_queued_root_effects,
@ -45,7 +46,7 @@ export class Batch {
/** @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null} */ /** @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null} */
// TODO replace with Promise.withResolvers once supported widely enough // TODO replace with Promise.withResolvers once supported widely enough
deferred = null; #deferred = null;
/** @type {Effect[]} */ /** @type {Effect[]} */
async_effects = []; async_effects = [];
@ -164,7 +165,7 @@ export class Batch {
flush_queued_effects(render_effects); flush_queued_effects(render_effects);
flush_queued_effects(effects); flush_queued_effects(effects);
this.deferred?.resolve(); this.#deferred?.resolve();
} }
} else { } else {
for (const e of this.render_effects) set_signal_status(e, CLEAN); for (const e of this.render_effects) set_signal_status(e, CLEAN);
@ -280,6 +281,10 @@ export class Batch {
return false; return false;
} }
settled() {
return (this.#deferred ??= deferred()).promise;
}
static ensure() { static ensure() {
if (current_batch === null) { if (current_batch === null) {
if (batches.size === 0) { if (batches.size === 0) {

@ -1,12 +1,6 @@
/** @import { Derived, Effect, Reaction, Signal, Source, Value } from '#client' */ /** @import { Derived, Effect, Reaction, Signal, Source, Value } from '#client' */
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
import { import { define_property, get_descriptors, get_prototype_of, index_of } from '../shared/utils.js';
deferred,
define_property,
get_descriptors,
get_prototype_of,
index_of
} from '../shared/utils.js';
import { import {
destroy_block_effect_children, destroy_block_effect_children,
destroy_effect_children, destroy_effect_children,
@ -759,7 +753,7 @@ export async function tick() {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
export function settled() { export function settled() {
return (Batch.ensure().deferred ??= deferred()).promise; return Batch.ensure().settled();
} }
/** /**

Loading…
Cancel
Save