Scheduler
Ce contenu n’est pas encore disponible dans votre langue.
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.
Implements
Section titled “Implements”Properties
Section titled “Properties”onError?
Section titled “onError?”
optionalonError?: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.
Accessors
Section titled “Accessors”isVirtual
Section titled “isVirtual”Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”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.
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”scheduleAtFixedRate()
Section titled “scheduleAtFixedRate()”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”initialDelayMs
Section titled “initialDelayMs”number
intervalMs
Section titled “intervalMs”number
target
Section titled “target”ActorRef<T>
message
Section titled “message”T
sender?
Section titled “sender?”ActorRef<unknown> | null = null
Returns
Section titled “Returns”scheduleAtFixedRateFunction()
Section titled “scheduleAtFixedRateFunction()”scheduleAtFixedRateFunction(
initialDelayMs,intervalMs,task):Cancellable
Defined in: src/Scheduler.ts:310
Parameters
Section titled “Parameters”initialDelayMs
Section titled “initialDelayMs”number
intervalMs
Section titled “intervalMs”number
() => void
Returns
Section titled “Returns”scheduleOnce()
Section titled “scheduleOnce()”scheduleOnce<
T>(delayMs,target,message,sender?):Cancellable
Defined in: src/Scheduler.ts:285
Deliver a message once after a delay.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”delayMs
Section titled “delayMs”number
target
Section titled “target”ActorRef<T>
message
Section titled “message”T
sender?
Section titled “sender?”ActorRef<unknown> | null = null
Returns
Section titled “Returns”scheduleOnceFunction()
Section titled “scheduleOnceFunction()”scheduleOnceFunction(
delayMs,task):Cancellable
Defined in: src/Scheduler.ts:295
Run a user-supplied function once after a delay.
Parameters
Section titled “Parameters”delayMs
Section titled “delayMs”number
() => void
