MCPcopy Create free account
hub / github.com/Effect-TS/effect / MixedScheduler

Class MixedScheduler

packages/effect/src/Scheduler.ts:222–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220 * @since 2.0.0
221 */
222export class MixedScheduler implements Scheduler {
223 readonly executionMode: "sync" | "async"
224 readonly setImmediate: (f: () => void) => () => void
225
226 constructor(
227 executionMode: "sync" | "async" = "async",
228 setImmediateFn?: (f: () => void) => () => void
229 ) {
230 this.executionMode = executionMode
231 this.setImmediate = setImmediateFn ?? (executionMode === "sync" ? setMicrotask : setImmediate)
232 }
233
234 /**
235 * Returns whether the fiber has reached its operation budget and should yield.
236 *
237 * **When to use**
238 *
239 * Use to decide whether a fiber should yield after consuming its current
240 * operation budget.
241 *
242 * @since 2.0.0
243 */
244 shouldYield(fiber: Fiber.Fiber<unknown, unknown>) {
245 return fiber.currentOpCount >= fiber.cache.maxOpsBeforeYield
246 }
247
248 /**
249 * Creates a dispatcher that schedules work through this scheduler.
250 *
251 * **When to use**
252 *
253 * Use when you need a standalone dispatcher from a scheduler instance, for
254 * example in tests that enqueue tasks and then flush them deterministically.
255 *
256 * @since 4.0.0
257 */
258 makeDispatcher() {
259 return new MixedSchedulerDispatcher(this.setImmediate)
260 }
261}
262
263class MixedSchedulerDispatcher implements SchedulerDispatcher {
264 // Sorted by priority, each bucket holding its tasks in FIFO order

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected