/** * @since 1.0.0 */ import type * as Context from "@effect/data/Context" import type { Inspectable } from "@effect/data/Inspectable" import type { Pipeable } from "@effect/data/Pipeable" import type { Cause } from "@effect/io/Cause" import type * as Effect from "@effect/io/Effect" import type * as Exit from "@effect/io/Exit" import type * as Fiber from "@effect/io/Fiber" import type * as FiberId from "@effect/io/FiberId" import type * as FiberRefs from "@effect/io/FiberRefs" import * as internal from "@effect/io/internal/runtime" import type * as RuntimeFlags from "@effect/io/RuntimeFlags" import type { Scheduler } from "@effect/io/Scheduler" /** * @since 1.0.0 * @category models */ export interface AsyncFiberException { readonly _tag: "AsyncFiberException" readonly fiber: Fiber.RuntimeFiber } /** * @since 1.0.0 * @category models */ export interface Cancel { (fiberId?: FiberId.FiberId, onExit?: (exit: Exit.Exit) => void): void } /** * @since 1.0.0 * @category models */ export interface Runtime extends Pipeable { /** * The context used as initial for forks */ readonly context: Context.Context /** * The runtime flags used as initial for forks */ readonly runtimeFlags: RuntimeFlags.RuntimeFlags /** * The fiber references used as initial for forks */ readonly fiberRefs: FiberRefs.FiberRefs } /** * @since 1.0.0 * @category models */ export interface RunForkOptions { scheduler?: Scheduler updateRefs?: (refs: FiberRefs.FiberRefs, fiberId: FiberId.Runtime) => FiberRefs.FiberRefs } /** * Executes the effect using the provided Scheduler or using the global * Scheduler if not provided * * @since 1.0.0 * @category execution */ export const runFork: ( runtime: Runtime ) => (self: Effect.Effect, options?: RunForkOptions | undefined) => Fiber.RuntimeFiber = internal.unsafeFork /** * Executes the effect synchronously returning the exit. * * This method is effectful and should only be invoked at the edges of your * program. * * @since 1.0.0 * @category execution */ export const runSyncExit: (runtime: Runtime) => (effect: Effect.Effect) => Exit.Exit = internal.unsafeRunSyncExit /** * 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. * * @since 1.0.0 * @category execution */ export const runSync: (runtime: Runtime) => (effect: Effect.Effect) => A = internal.unsafeRunSync /** * 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. * * @since 1.0.0 * @category execution */ export const runCallback: ( runtime: Runtime ) => ( effect: Effect.Effect, onExit?: ((exit: Exit.Exit) => void) | undefined ) => (fiberId?: FiberId.FiberId | undefined, onExit?: ((exit: Exit.Exit) => void) | undefined) => void = internal.unsafeRunCallback /** * 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. * * @since 1.0.0 * @category execution */ export const runPromise: (runtime: Runtime) => (effect: Effect.Effect) => Promise = internal.unsafeRunPromise /** * 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. * * @since 1.0.0 * @category execution */ export const runPromiseExit: ( runtime: Runtime ) => (effect: Effect.Effect) => Promise> = internal.unsafeRunPromiseExit /** * @since 1.0.0 * @category constructors */ export const defaultRuntime: Runtime = internal.defaultRuntime /** * @since 1.0.0 * @category constructors */ export const defaultRuntimeFlags: RuntimeFlags.RuntimeFlags = internal.defaultRuntimeFlags /** * @since 1.0.0 * @category constructors */ export const make: ( options: { readonly context: Context.Context readonly runtimeFlags: RuntimeFlags.RuntimeFlags readonly fiberRefs: FiberRefs.FiberRefs } ) => Runtime = internal.make /** * @since 1.0.0 * @category symbols */ export const FiberFailureId = Symbol.for("@effect/io/Runtime/FiberFailure") /** * @since 1.0.0 * @category symbols */ export type FiberFailureId = typeof FiberFailureId /** * @since 1.0.0 * @category symbols */ export const FiberFailureCauseId: unique symbol = internal.FiberFailureCauseId /** * @since 1.0.0 * @category exports */ export type FiberFailureCauseId = typeof FiberFailureCauseId /** * @since 1.0.0 * @category models */ export interface FiberFailure extends Error, Inspectable { readonly [FiberFailureId]: FiberFailureId readonly [FiberFailureCauseId]: Cause } /** * @since 1.0.0 * @category guards */ export const isAsyncFiberException: (u: unknown) => u is AsyncFiberException = internal.isAsyncFiberException /** * @since 1.0.0 * @category guards */ export const isFiberFailure: (u: unknown) => u is FiberFailure = internal.isFiberFailure /** * @since 1.0.0 * @category constructors */ export const makeFiberFailure: (cause: Cause) => FiberFailure = internal.fiberFailure