@gluonjs/reactivity / packages/reactivity/src / nextTick
Function: nextTick()
Call Signature
nextTick():
Promise<void>
Returns
Promise<void>
Call Signature
nextTick<
T>(callback):Promise<T>
Type Parameters
T
T
Parameters
callback
() => T | PromiseLike<T>
Returns
Promise<T>
Example
Wait until all currently queued pre-, update-, and post-flush work has completed before reading the settled result:
import {
invalidateJob,
nextTick,
queueJob,
queuePostFlushCallback,
queuePreFlushCallback,
type EffectFlush,
type FlushPhase,
type SchedulerJob,
type SchedulerJobOptions,
} from '@gluonjs/reactivity';
const order: string[] = [];
const cancelled: SchedulerJob = () => order.push('cancelled');
const update: SchedulerJob = () => order.push('update');
const phase: FlushPhase = 'update';
const flush: EffectFlush = 'post';
const options: SchedulerJobOptions = { phase, id: 10 };
queuePreFlushCallback(() => order.push('pre'));
queueJob(update, options);
queueJob(cancelled);
invalidateJob(cancelled);
queuePostFlushCallback(() => order.push(flush));
await nextTick();
console.log(order); // ['pre', 'update', 'post']