Runtime
Constructors
Signature
declare const defaultRuntime: Runtime<never>Signature
declare const defaultRuntimeFlags: RuntimeFlags.RuntimeFlagsSignature
declare const make: <R>(options: { readonly context: Context.Context<R>; readonly fiberRefs: FiberRefs.FiberRefs; readonly runtimeFlags: RuntimeFlags.RuntimeFlags;}) => Runtime<R>Signature
declare const makeFiberFailure: <E>(cause: Cause<E>) => FiberFailureContext
Signature
declare const provideService: { <I, S>(tag: Tag<I, S>, service: S): <R>(self: Runtime<R>) => Runtime<I | R>; <R, I, S>(self: Runtime<R>, tag: Tag<I, S>, service: S): Runtime<R | I>;}Example
import { Context, Runtime } from "effect"
class Name extends Context.Tag("Name")<Name, string>() {}
const runtime: Runtime.Runtime<Name> = Runtime.defaultRuntime.pipe( Runtime.provideService(Name, "John"))Signature
declare const updateContext: { <R, R2>(f: (context: Context<R>) => Context<R2>): (self: Runtime<R>) => Runtime<R2>; <R, R2>(self: Runtime<R>, f: (context: Context<R>) => Context<R2>): Runtime<R2>;}Execution
Executes the effect asynchronously, eventually passing the exit value to the specified callback.
This method is effectful and should only be invoked at the edges of your program.
Signature
declare const runCallback: { <R>(runtime: Runtime<R>): <A, E>(effect: Effect<A, E, R>, options?: RunCallbackOptions<A, E>) => (fiberId?: FiberId, options?: RunCallbackOptions<A, E>) => void; <R, A, E>(runtime: Runtime<R>, effect: Effect<A, E, R>, options?: RunCallbackOptions<A, E>): (fiberId?: FiberId, options?: RunCallbackOptions<A, E>) => void;}Executes the effect using the provided Scheduler or using the global Scheduler if not provided
Signature
declare const runFork: { <R>(runtime: Runtime<R>): <A, E>(effect: Effect<A, E, R>, options?: RunForkOptions) => RuntimeFiber<A, E>; <R, A, E>(runtime: Runtime<R>, effect: Effect<A, E, R>, options?: RunForkOptions): RuntimeFiber<A, E>;}Runs the Effect, returning a JavaScript Promise that will be resolved
with the value of the effect once the effect has been executed, or will be
rejected with the first error or exception throw by the effect.
This method is effectful and should only be used at the edges of your program.
Signature
declare const runPromise: { <R>(runtime: Runtime<R>): <A, E>(effect: Effect<A, E, R>, options?: { readonly signal?: AbortSignal; }) => Promise<A>; <R, A, E>(runtime: Runtime<R>, effect: Effect<A, E, R>, options?: { readonly signal?: AbortSignal; }): Promise<A>;}Runs the Effect, returning a JavaScript Promise that will be resolved
with the Exit state of the effect once the effect has been executed.
This method is effectful and should only be used at the edges of your program.
Signature
declare const runPromiseExit: { <R>(runtime: Runtime<R>): <A, E>(effect: Effect<A, E, R>, options?: { readonly signal?: AbortSignal; }) => Promise<Exit<A, E>>; <R, A, E>(runtime: Runtime<R>, effect: Effect<A, E, R>, options?: { readonly signal?: AbortSignal; }): Promise<Exit<A, E>>;}Executes the effect synchronously throwing in case of errors or async boundaries.
This method is effectful and should only be invoked at the edges of your program.
Signature
declare const runSync: { <A, E, R>(runtime: Runtime<R>, effect: Effect<A, E, R>): A; <R>(runtime: Runtime<R>): <A, E>(effect: Effect<A, E, R>) => A;}Executes the effect synchronously returning the exit.
This method is effectful and should only be invoked at the edges of your program.
Signature
declare const runSyncExit: { <A, E, R>(runtime: Runtime<R>, effect: Effect<A, E, R>): Exit<A, E>; <R>(runtime: Runtime<R>): <A, E>(effect: Effect<A, E, R>) => Exit<A, E>;}Exports
FiberFailureCauseId
typeSignature
type FiberFailureCauseId = typeof FiberFailureCauseIdFiber Refs
Signature
declare const deleteFiberRef: { <A>(fiberRef: FiberRef<A>): <R>(self: Runtime<R>) => Runtime<R>; <R, A>(self: Runtime<R>, fiberRef: FiberRef<A>): Runtime<R>;}Example
import { Effect, FiberRef, Runtime } from "effect"
const ref = FiberRef.unsafeMake(0)
const updatedRuntime = Runtime.defaultRuntime.pipe( Runtime.setFiberRef(ref, 1), Runtime.deleteFiberRef(ref))
// returns 0const result = Runtime.runSync(updatedRuntime)(FiberRef.get(ref))Signature
declare const setFiberRef: { <A>(fiberRef: FiberRef<A>, value: A): <R>(self: Runtime<R>) => Runtime<R>; <R, A>(self: Runtime<R>, fiberRef: FiberRef<A>, value: A): Runtime<R>;}Example
import { Effect, FiberRef, Runtime } from "effect"
const ref = FiberRef.unsafeMake(0)
const updatedRuntime = Runtime.defaultRuntime.pipe( Runtime.setFiberRef(ref, 1))
// returns 1const result = Runtime.runSync(updatedRuntime)(FiberRef.get(ref))Signature
declare const updateFiberRefs: { (f: (fiberRefs: FiberRefs) => FiberRefs): <R>(self: Runtime<R>) => Runtime<R>; <R>(self: Runtime<R>, f: (fiberRefs: FiberRefs) => FiberRefs): Runtime<R>;}Guards
Models
AsyncFiberException
interfaceSignature
interface AsyncFiberException<out A, out E = never> { readonly _tag: "AsyncFiberException"; readonly fiber: RuntimeFiber<A, E>;}Signature
interface Cancel<out A, out E = never> { (fiberId?: FiberId, options?: RunCallbackOptions<A, E>): void;}FiberFailure
interfaceSignature
interface FiberFailure extends Error, Inspectable { readonly [FiberFailureCauseId]: Cause<unknown>; readonly [FiberFailureId]: typeof FiberFailureId;}RunCallbackOptions
interfaceSignature
interface RunCallbackOptions<in A, in E = never> extends RunForkOptions { readonly onExit?: (exit: Exit<A, E>) => void;}RunForkOptions
interfaceSignature
interface RunForkOptions { readonly immediate?: boolean; readonly scheduler?: Scheduler; readonly scope?: Scope; readonly updateRefs?: (refs: FiberRefs, fiberId: Runtime) => FiberRefs;}Signature
interface Runtime<in R> extends Pipeable { readonly context: Context<R>; readonly fiberRefs: FiberRefs; readonly runtimeFlags: RuntimeFlags;}Other
Runtime Flags
Signature
declare const disableRuntimeFlag: { (flag: RuntimeFlag): <R>(self: Runtime<R>) => Runtime<R>; <R>(self: Runtime<R>, flag: RuntimeFlag): Runtime<R>;}Signature
declare const enableRuntimeFlag: { (flag: RuntimeFlag): <R>(self: Runtime<R>) => Runtime<R>; <R>(self: Runtime<R>, flag: RuntimeFlag): Runtime<R>;}Signature
declare const updateRuntimeFlags: { (f: (flags: RuntimeFlags) => RuntimeFlags): <R>(self: Runtime<R>) => Runtime<R>; <R>(self: Runtime<R>, f: (flags: RuntimeFlags) => RuntimeFlags): Runtime<R>;}Symbols
Signature
declare const FiberFailureCauseId: unique symbolSignature
declare const FiberFailureId: typeof FiberFailureIdFiberFailureId
typeSignature
type FiberFailureId = typeof FiberFailureId