Skip to main content Link Search Menu Expand Document (external link)

Runtime.ts overview

Since v2.0.0


Exports Grouped by Category


constructors

defaultRuntime

Signature

declare const defaultRuntime: Runtime<never>

Source

Since v2.0.0

defaultRuntimeFlags

Signature

declare const defaultRuntimeFlags: RuntimeFlags.RuntimeFlags

Source

Since v2.0.0

make

Signature

declare const make: <R>(options: {
  readonly context: Context.Context<R>
  readonly runtimeFlags: RuntimeFlags.RuntimeFlags
  readonly fiberRefs: FiberRefs.FiberRefs
}) => Runtime<R>

Source

Since v2.0.0

makeFiberFailure

Signature

declare const makeFiberFailure: <E>(cause: Cause<E>) => FiberFailure

Source

Since v2.0.0

context

provideService

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 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>
}

Source

Since v2.0.0

updateContext

Signature

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>
}

Source

Since 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

declare const runCallback: {
  <R>(
    runtime: Runtime<R>
  ): <A, E>(
    effect: Effect.Effect<A, E, R>,
    options?: RunCallbackOptions<A, E> | undefined
  ) => (fiberId?: FiberId.FiberId, options?: RunCallbackOptions<A, E> | undefined) => void
  <R, A, E>(
    runtime: Runtime<R>,
    effect: Effect.Effect<A, E, R>,
    options?: RunCallbackOptions<A, E> | undefined
  ): (fiberId?: FiberId.FiberId, options?: RunCallbackOptions<A, E> | undefined) => void
}

Source

Since v2.0.0

runFork

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.Effect<A, E, R>, options?: RunForkOptions | undefined) => Fiber.RuntimeFiber<A, E>
  <R, A, E>(
    runtime: Runtime<R>,
    effect: Effect.Effect<A, E, R>,
    options?: RunForkOptions | undefined
  ): Fiber.RuntimeFiber<A, E>
}

Source

Since 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

declare const runPromise: {
  <R>(
    runtime: Runtime<R>
  ): <A, E>(effect: Effect.Effect<A, E, R>, options?: { readonly signal?: AbortSignal } | undefined) => Promise<A>
  <R, A, E>(
    runtime: Runtime<R>,
    effect: Effect.Effect<A, E, R>,
    options?: { readonly signal?: AbortSignal } | undefined
  ): Promise<A>
}

Source

Since 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

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>>
  <R, A, E>(
    runtime: Runtime<R>,
    effect: Effect.Effect<A, E, R>,
    options?: { readonly signal?: AbortSignal } | undefined
  ): Promise<Exit.Exit<A, E>>
}

Source

Since 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

declare const runSync: {
  <A, E, R>(runtime: Runtime<R>, effect: Effect.Effect<A, E, R>): A
  <R>(runtime: Runtime<R>): <A, E>(effect: Effect.Effect<A, E, R>) => A
}

Source

Since 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

declare const runSyncExit: {
  <A, E, R>(runtime: Runtime<R>, effect: Effect.Effect<A, E, R>): Exit.Exit<A, E>
  <R>(runtime: Runtime<R>): <A, E>(effect: Effect.Effect<A, E, R>) => Exit.Exit<A, E>
}

Source

Since v2.0.0

exports

FiberFailureCauseId (type alias)

Signature

type FiberFailureCauseId = typeof FiberFailureCauseId

Source

Since v2.0.0

fiber refs

deleteFiberRef

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))

Signature

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>
}

Source

Since v2.0.0

setFiberRef

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))

Signature

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>
}

Source

Since v2.0.0

updateFiberRefs

Signature

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>
}

Source

Since v2.0.0

guards

isAsyncFiberException

Signature

declare const isAsyncFiberException: (u: unknown) => u is AsyncFiberException<unknown, unknown>

Source

Since v2.0.0

isFiberFailure

Signature

declare const isFiberFailure: (u: unknown) => u is FiberFailure

Source

Since v2.0.0

models

AsyncFiberException (interface)

Signature

export interface AsyncFiberException<out A, out E = never> {
  readonly _tag: "AsyncFiberException"
  readonly fiber: Fiber.RuntimeFiber<A, E>
}

Source

Since v2.0.0

Cancel (interface)

Signature

export interface Cancel<out A, out E = never> {
  (fiberId?: FiberId.FiberId, options?: RunCallbackOptions<A, E> | undefined): void
}

Source

Since v2.0.0

FiberFailure (interface)

Signature

export interface FiberFailure extends Error, Inspectable {
  readonly [FiberFailureId]: FiberFailureId
  readonly [FiberFailureCauseId]: Cause<unknown>
}

Source

Since 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
}

Source

Since 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
}

Source

Since 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
}

Source

Since v2.0.0

runtime flags

disableRuntimeFlag

Signature

declare const disableRuntimeFlag: {
  (flag: RuntimeFlags.RuntimeFlag): <R>(self: Runtime<R>) => Runtime<R>
  <R>(self: Runtime<R>, flag: RuntimeFlags.RuntimeFlag): Runtime<R>
}

Source

Since v2.0.0

enableRuntimeFlag

Signature

declare const enableRuntimeFlag: {
  (flag: RuntimeFlags.RuntimeFlag): <R>(self: Runtime<R>) => Runtime<R>
  <R>(self: Runtime<R>, flag: RuntimeFlags.RuntimeFlag): Runtime<R>
}

Source

Since v2.0.0

updateRuntimeFlags

Signature

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>
}

Source

Since v2.0.0

symbols

FiberFailureCauseId

Signature

declare const FiberFailureCauseId: unique symbol

Source

Since v2.0.0

FiberFailureId

Signature

declare const FiberFailureId: unique symbol

Source

Since v2.0.0

FiberFailureId (type alias)

Signature

type FiberFailureId = typeof FiberFailureId

Source

Since v2.0.0

utils

Runtime (namespace)

Source

Since v3.12.0

Context (type alias)

Signature

type Context<T> = [T] extends [Runtime<infer R>] ? R : never

Source

Since v3.12.0