Context.Reference<number>Context reference that controls the maximum number of operations a fiber can perform before yielding control back to the scheduler.
When to use
Use to tune scheduler fairness for CPU-bound fibers by changing the scheduler operation budget that triggers a yield.
Details
The default value is 2048 operations, which balances performance and
fairness by helping prevent long-running fibers from monopolizing the
execution thread.
export const const MaxOpsBeforeYield: Context.Reference<number>const MaxOpsBeforeYield: {
defaultValue: () => Shape;
of: (this: void, self: number) => number;
context: (self: number) => Context.Context<never>;
use: (f: (service: number) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: number) => A) => Effect<A, never, never>;
Identifier: Identifier;
Service: Shape;
key: string;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Context reference that controls the maximum number of operations a fiber
can perform before yielding control back to the scheduler.
When to use
Use to tune scheduler fairness for CPU-bound fibers by changing the scheduler
operation budget that triggers a yield.
Details
The default value is 2048 operations, which balances performance and
fairness by helping prevent long-running fibers from monopolizing the
execution thread.
MaxOpsBeforeYield = import ContextContext.const Reference: <Service>(
key: string,
options: {
readonly defaultValue: () => Service
}
) => Reference<Service>
Creates a context key with a default value.
When to use
Use when you need to define a context key with a lazily computed default
value.
Details
Context.Reference allows you to create a key that can hold a value. You
can provide a default value for the service, which will automatically be used
when the context is accessed, or override it with a custom implementation
when needed. The default value is computed lazily and cached on the
reference.
Example (Creating references with default values)
import { Context } from "effect"
// Create a reference with a default value
const LoggerRef = Context.Reference("Logger", {
defaultValue: () => ({ log: (msg: string) => console.log(msg) })
})
// The reference provides the default value when accessed from an empty context
const context = Context.empty()
const logger = Context.get(context, LoggerRef)
// You can also override the default value
const customContext = Context.make(LoggerRef, {
log: (msg: string) => `Custom: ${msg}`
})
const customLogger = Context.get(customContext, LoggerRef)
Reference<number>("effect/Scheduler/MaxOpsBeforeYield", {
defaultValue: () => numberdefaultValue: () => 2048
})