createScheduler
Stable · since 0.1.0
Constructs the dispatch scheduler used internally by the runtime. The two built-in strategies — 'microtask' and 'sync' — cover almost every real-world need; createScheduler is exposed for custom runtime composition, low-level tests, and benchmarking.
The microtask scheduler batches enqueued tasks and drains them in queueMicrotask. The sync scheduler runs tasks immediately, in the caller’s stack.
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
strategy | 'sync' | 'microtask' | Dispatch policy. |
Returns
Section titled “Returns”A SchedulerImpl:
| Method | Description |
|---|---|
enqueue(task) | Schedule a thunk. Microtask: batches into the next microtask drain. Sync: runs immediately. |
flush() | Drain any pending tasks now. For tests and fireSync. Sync scheduler keeps no queue, so its flush is a no-op. |
Examples
Section titled “Examples”Microtask batching
Section titled “Microtask batching”Synchronous dispatch
Section titled “Synchronous dispatch”Error isolation in microtask mode
Section titled “Error isolation in microtask mode”Related
Section titled “Related” createRuntime The runtime picks a scheduler per trigger automatically.
createFakeScheduler Virtual-clock scheduler for tests.
Scheduling guide Microtask vs sync — when to pick which.
Concurrency strategies How async handlers interleave under each strategy.