HybridDispatcher
Esta página aún no está disponible en tu idioma.
Defined in: src/Dispatcher.ts:139
Wakes actors on the microtask queue, and spends every DEFAULT_HYBRID_DISPATCHER_YIELD_UNITS-th unit on a macrotask so the event loop still advances. This is the default dispatcher.
MicrotaskDispatcher is the fast half on its own, and unusable on its own: microtasks drain completely before the loop reaches timers or I/O, so two actors volleying re-queue a microtask from inside a microtask forever and nothing else ever runs. That is not hypothetical — it is the shape of the throttle-resume livelock in #1167. ImmediateDispatcher is the fair half, at ~2.4 µs a hop, which an alternating request/response pays per message because there is never a second message in the mailbox to amortise it across.
The budget is what joins them. Consecutive units scheduled as microtasks are
counted, and on reaching the budget one unit goes through setImmediate
instead, resetting the count — so no chain of actor turns can outrun the
event loop by more than the budget, and in the worst case this dispatcher
behaves exactly like the immediate one rather than like something new.
The count is per dispatcher, not per actor, because the microtask chain is the union across every actor scheduled here: two cells volleying would each see a count of 1 forever under a per-cell budget, which is exactly the case the budget exists to bound. The system’s default dispatcher is a single shared instance, so the counter sees the whole chain.
It counts rather than clocks deliberately: a performance.now() per
execute would put back, on the scheduling path, the same kind of
unconditional clock read #411 removed from the receive path.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new HybridDispatcher(
yieldEvery?):HybridDispatcher
Defined in: src/Dispatcher.ts:166
Parameters
Section titled “Parameters”yieldEvery?
Section titled “yieldEvery?”number = DEFAULT_HYBRID_DISPATCHER_YIELD_UNITS
Returns
Section titled “Returns”HybridDispatcher
Properties
Section titled “Properties”
readonlyid:"hybrid-dispatcher"='hybrid-dispatcher'
Defined in: src/Dispatcher.ts:140
Implementation of
Section titled “Implementation of”onError?
Section titled “onError?”
optionalonError?:DispatcherErrorSink
Defined in: src/Dispatcher.ts:141
Where a unit of work that threw is reported. Optional so a
third-party dispatcher stays a two-member implementation: an unset
sink falls back to console.error, which is what every dispatcher
did before the slot existed.
ActorSystem fills it in with ??=, so a sink the owner set
deliberately survives being handed to a system.
Implementation of
Section titled “Implementation of”yieldEvery
Section titled “yieldEvery”
readonlyyieldEvery:number=DEFAULT_HYBRID_DISPATCHER_YIELD_UNITS
Defined in: src/Dispatcher.ts:166
Methods
Section titled “Methods”execute()
Section titled “execute()”execute(
task):void
Defined in: src/Dispatcher.ts:168
Schedule a unit of work to be executed asynchronously.
Parameters
Section titled “Parameters”() => void | Promise<void>
Returns
Section titled “Returns”void
