Scheduler API reference for Scheduler in Semantic UI's reactivity system clock Guide

Scheduler

Scheduler is a core class in Semantic UI’s reactivity system that manages the scheduling and execution of reactive computations. It handles the queueing and flushing of reactions, ensuring efficient updates when reactive dependencies change.

The Scheduler class is responsible for:

  • Managing the execution of reactive computations
  • Ensuring reactions run in the correct order
  • Providing debugging information
  • Handling the microtask queue for reaction scheduling
  • Managing post-flush callbacks

Advanced Use Only - Scheduler is primarily used internally by Signal and Reaction. Most developers should not need to interact with it directly unless building advanced reactive systems or meta-frameworks.

Static Properties

current

The currently executing reaction.

Syntax

Scheduler.current

Returns

Reaction | null - The currently executing reaction, or null if no reaction is executing.

Usage

import { Scheduler } from '@semantic-ui/reactivity';
console.log(Scheduler.current); // null if outside a reaction

pendingReactions

Set of reactions waiting to be executed.

Syntax

Scheduler.pendingReactions

Returns

Set - The set of pending reactions.

Static Methods

scheduleReaction

Schedules a reaction to be executed during the next flush cycle.

Syntax

Scheduler.scheduleReaction(reaction)

Parameters

NameTypeDescription
reactionReactionThe reaction to schedule for execution

Usage

import { Scheduler, Reaction } from '@semantic-ui/reactivity';
const reaction = Reaction.create(() => {
console.log('Reaction executed');
});
Scheduler.scheduleReaction(reaction);

scheduleFlush

Schedules a flush of all pending reactions using the microtask queue.

Syntax

Scheduler.scheduleFlush()

Usage

import { Scheduler } from '@semantic-ui/reactivity';
Scheduler.scheduleFlush();

flush

Immediately executes all pending reactions and afterFlush callbacks.

Syntax

Scheduler.flush()

Usage

import { Scheduler } from '@semantic-ui/reactivity';
Scheduler.flush(); // Executes all pending reactions immediately

afterFlush

Registers a callback to be executed after the next flush cycle completes.

Syntax

Scheduler.afterFlush(callback)

Parameters

NameTypeDescription
callbackFunctionFunction to execute after flush completes

Usage

import { Scheduler } from '@semantic-ui/reactivity';
Scheduler.afterFlush(() => {
console.log('Flush completed');
});

getSource

Returns the stack trace of the current reaction for debugging purposes.

Syntax

Scheduler.getSource()

Returns

string | undefined - The stack trace of the current reaction, or undefined if no reaction is running.

Usage

import { Scheduler, Reaction } from '@semantic-ui/reactivity';
Reaction.create(() => {
console.log(Scheduler.getSource());
});