Runtime overview
Added in v2.0.0
Table of contents
constructors
defaultRuntime
Signature
export declare const defaultRuntime: Runtime<never>
Added in v2.0.0
defaultRuntimeFlags
Signature
export declare const defaultRuntimeFlags: RuntimeFlags.RuntimeFlags
Added in v2.0.0
make
Signature
export declare const make: <R>(options: {
readonly context: Context.Context<R>
readonly runtimeFlags: RuntimeFlags.RuntimeFlags
readonly fiberRefs: FiberRefs.FiberRefs
}) => Runtime<R>
Added in v2.0.0
makeFiberFailure
Signature
export declare const makeFiberFailure: <E>(cause: Cause<E>) => FiberFailure
Added in v2.0.0
context
provideService
Signature
export declare const provideService: {
<I, S>(tag: Context.Tag<I, S>, service: S): <R>(self: Runtime<R>) => Runtime<I | R>
<R, I, S>(self: Runtime<R>, tag: Context.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"))
Added in v2.0.0
updateContext
Signature
export declare const updateContext: {
<R, R2>(f: (context: Context.Context<R>) => Context.Context<R2>): (self: Runtime<R>) => Runtime<R2>
<R, R2>(self: Runtime<R>, f: (context: Context.Context<R>) => Context.Context<R2>): Runtime<R2>
}
Added in v2.0.0
execution
runCallback
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
export declare const runCallback: <R>(
runtime: Runtime<R>
) => <A, E>(
effect: Effect.Effect<A, E, R>,
options?: RunCallbackOptions<A, E> | undefined
) => (fiberId?: FiberId.FiberId | undefined, options?: RunCallbackOptions<A, E> | undefined) => void
Added in v2.0.0
runFork
Executes the effect using the provided Scheduler or using the global Scheduler if not provided
Signature
export declare const runFork: <R>(
runtime: Runtime<R>
) => <A, E>(self: Effect.Effect<A, E, R>, options?: RunForkOptions) => Fiber.RuntimeFiber<A, E>
Added in v2.0.0
runPromise
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
export declare const runPromise: <R>(
runtime: Runtime<R>
) => <A, E>(effect: Effect.Effect<A, E, R>, options?: { readonly signal?: AbortSignal } | undefined) => Promise<A>
Added in v2.0.0
runPromiseExit
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
export declare const runPromiseExit: <R>(
runtime: Runtime<R>
) => <A, E>(
effect: Effect.Effect<A, E, R>,
options?: { readonly signal?: AbortSignal } | undefined
) => Promise<Exit.Exit<A, E>>
Added in v2.0.0
runSync
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
export declare const runSync: <R>(runtime: Runtime<R>) => <A, E>(effect: Effect.Effect<A, E, R>) => A
Added in v2.0.0
runSyncExit
Executes the effect synchronously returning the exit.
This method is effectful and should only be invoked at the edges of your program.
Signature
export declare const runSyncExit: <R>(runtime: Runtime<R>) => <A, E>(effect: Effect.Effect<A, E, R>) => Exit.Exit<A, E>
Added in v2.0.0
exports
FiberFailureCauseId (type alias)
Signature
export type FiberFailureCauseId = typeof FiberFailureCauseId
Added in v2.0.0
fiber refs
deleteFiberRef
Signature
export declare const deleteFiberRef: {
<A>(fiberRef: FiberRef.FiberRef<A>): <R>(self: Runtime<R>) => Runtime<R>
<R, A>(self: Runtime<R>, fiberRef: 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 0
const result = Runtime.runSync(updatedRuntime)(FiberRef.get(ref))
Added in v2.0.0
setFiberRef
Signature
export declare const setFiberRef: {
<A>(fiberRef: FiberRef.FiberRef<A>, value: A): <R>(self: Runtime<R>) => Runtime<R>
<R, A>(self: Runtime<R>, fiberRef: 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 1
const result = Runtime.runSync(updatedRuntime)(FiberRef.get(ref))
Added in v2.0.0
updateFiberRefs
Signature
export declare const updateFiberRefs: {
(f: (fiberRefs: FiberRefs.FiberRefs) => FiberRefs.FiberRefs): <R>(self: Runtime<R>) => Runtime<R>
<R>(self: Runtime<R>, f: (fiberRefs: FiberRefs.FiberRefs) => FiberRefs.FiberRefs): Runtime<R>
}
Added in v2.0.0
guards
isAsyncFiberException
Signature
export declare const isAsyncFiberException: (u: unknown) => u is AsyncFiberException<unknown, unknown>
Added in v2.0.0
isFiberFailure
Signature
export declare const isFiberFailure: (u: unknown) => u is FiberFailure
Added in v2.0.0
models
AsyncFiberException (interface)
Signature
export interface AsyncFiberException<out A, out E = never> {
readonly _tag: "AsyncFiberException"
readonly fiber: Fiber.RuntimeFiber<A, E>
}
Added in v2.0.0
Cancel (interface)
Signature
export interface Cancel<out A, out E = never> {
(fiberId?: FiberId.FiberId, options?: RunCallbackOptions<A, E> | undefined): void
}
Added in v2.0.0
FiberFailure (interface)
Signature
export interface FiberFailure extends Error, Inspectable {
readonly [FiberFailureId]: FiberFailureId
readonly [FiberFailureCauseId]: Cause<unknown>
}
Added in v2.0.0
RunCallbackOptions (interface)
Signature
export interface RunCallbackOptions<in A, in E = never> extends RunForkOptions {
readonly onExit?: ((exit: Exit.Exit<A, E>) => void) | undefined
}
Added in v2.0.0
RunForkOptions (interface)
Signature
export interface RunForkOptions {
readonly scheduler?: Scheduler | undefined
readonly updateRefs?: ((refs: FiberRefs.FiberRefs, fiberId: FiberId.Runtime) => FiberRefs.FiberRefs) | undefined
readonly immediate?: boolean
readonly scope?: Scope
}
Added in v2.0.0
Runtime (interface)
Signature
export interface Runtime<in R> extends Pipeable {
/**
* The context used as initial for forks
*/
readonly context: Context.Context<R>
/**
* The runtime flags used as initial for forks
*/
readonly runtimeFlags: RuntimeFlags.RuntimeFlags
/**
* The fiber references used as initial for forks
*/
readonly fiberRefs: FiberRefs.FiberRefs
}
Added in v2.0.0
runtime flags
disableRuntimeFlag
Signature
export declare const disableRuntimeFlag: {
(flag: RuntimeFlags.RuntimeFlag): <R>(self: Runtime<R>) => Runtime<R>
<R>(self: Runtime<R>, flag: RuntimeFlags.RuntimeFlag): Runtime<R>
}
Added in v2.0.0
enableRuntimeFlag
Signature
export declare const enableRuntimeFlag: {
(flag: RuntimeFlags.RuntimeFlag): <R>(self: Runtime<R>) => Runtime<R>
<R>(self: Runtime<R>, flag: RuntimeFlags.RuntimeFlag): Runtime<R>
}
Added in v2.0.0
updateRuntimeFlags
Signature
export declare const updateRuntimeFlags: {
(f: (flags: RuntimeFlags.RuntimeFlags) => RuntimeFlags.RuntimeFlags): <R>(self: Runtime<R>) => Runtime<R>
<R>(self: Runtime<R>, f: (flags: RuntimeFlags.RuntimeFlags) => RuntimeFlags.RuntimeFlags): Runtime<R>
}
Added in v2.0.0
symbols
FiberFailureCauseId
Signature
export declare const FiberFailureCauseId: typeof FiberFailureCauseId
Added in v2.0.0
FiberFailureId
Signature
export declare const FiberFailureId: typeof FiberFailureId
Added in v2.0.0
FiberFailureId (type alias)
Signature
export type FiberFailureId = typeof FiberFailureId
Added in v2.0.0