Zum Inhalt springen
Deutsch

Scheduler

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Defined in: src/Scheduler.ts:225

Time-based scheduler — a thin wrapper over setTimeout / setInterval, accurate enough for typical use and good enough for tests. Inject a ManualScheduler from the TestKit when you want fully deterministic time advancement. A delay longer than one host timer holds (~24.9 days) is armed as a chain of them, so it waits as long as it says (armChainedTimeout).

It is also the system’s Clock, and the two belong together for a reason: a component that arms a timer almost always also asks what time it is, and if those answers come from different sources the timer and the reading disagree. That was the state before this — ticks ran through a ManualScheduler while the code they drove read Date.now(), so a hundred advanced ticks all landed on the same real instant.

optional onError?: SchedulerErrorSink

Defined in: src/Scheduler.ts:271

Where a scheduled task that threw is reported. Optional so that a scheduler stays usable with no system at all — a bare new Scheduler() in a test, or one constructed before ActorSystem.create returns — and an unset sink falls back to console.error, which is what every scheduler did before the slot existed.

ActorSystem fills it in with ??=, so a sink the owner set deliberately survives being handed to a system through ActorSystemOptions.withScheduler.

get isVirtual(): boolean

Defined in: src/Scheduler.ts:258

Does time here move only when someone advances it?

Asked by the few places that would otherwise arm a raw setTimeout on a path hot enough to care. Routing a deadline through a scheduler buys exactly one thing — a test can advance past it — and a wall-clock scheduler cannot offer that, so where the answer is false those places keep the host timer.

Measured rather than assumed: arming every ask deadline through scheduleOnceFunction costs ~13% of ask-throughput (195k -> 170k ask/s, p50 2.8 -> 3.1 µs) for the SimpleCancellable, the live Set insert and delete, and the guarded closure. Keeping the dispatch but bypassing the scheduler restores the figure exactly, which is what isolates the cost to this path rather than to the lookup that reaches it.

boolean

now(): number

Defined in: src/Scheduler.ts:240

The wall clock. ManualScheduler overrides it with virtual time, which is what makes handing a component system.clock enough to make it testable.

number

Clock.now


scheduleAtFixedRate<T>(initialDelayMs, intervalMs, target, message, sender?): Cancellable

Defined in: src/Scheduler.ts:300

Deliver a message repeatedly at a fixed interval, after an initial delay.

T

number

number

ActorRef<T>

T

ActorRef<unknown> | null = null

Cancellable


scheduleAtFixedRateFunction(initialDelayMs, intervalMs, task): Cancellable

Defined in: src/Scheduler.ts:310

number

number

() => void

Cancellable


scheduleOnce<T>(delayMs, target, message, sender?): Cancellable

Defined in: src/Scheduler.ts:285

Deliver a message once after a delay.

T

number

ActorRef<T>

T

ActorRef<unknown> | null = null

Cancellable


scheduleOnceFunction(delayMs, task): Cancellable

Defined in: src/Scheduler.ts:295

Run a user-supplied function once after a delay.

number

() => void

Cancellable