Runtime
Constructors
defaultRuntime
Signature
declare const defaultRuntime: Runtime<never>;defaultRuntimeFlags
Signature
declare const defaultRuntimeFlags: RuntimeFlags.RuntimeFlags;Signature
declare const make: <R>(options: {
readonly context: Context.Context<R>;
readonly fiberRefs: FiberRefs.FiberRefs;
readonly runtimeFlags: RuntimeFlags.RuntimeFlags;
}) => Runtime<R>;makeFiberFailure
Signature
declare const makeFiberFailure: <E>(cause: Cause<E>) => FiberFailure;Context
provideService
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"),
)updateContext
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
runCallback
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>;
};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<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>;
};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<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;
};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<A, E, R>): Exit<A, E>;
<R>(runtime: Runtime<R>): <A, E>(effect: Effect<A, E, R>) => Exit<A, E>;
};Exports
FiberFailureCauseId type
Signature
type FiberFailureCauseId = typeof FiberFailureCauseId;Fiber Refs
deleteFiberRef
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 0
const result = Runtime.runSync(updatedRuntime)(FiberRef.get(ref))setFiberRef
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 1
const result = Runtime.runSync(updatedRuntime)(FiberRef.get(ref))updateFiberRefs
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
isAsyncFiberException
Signature
declare const isAsyncFiberException: (u: unknown) => u is AsyncFiberException<unknown, unknown>;isFiberFailure
Signature
declare const isFiberFailure: (u: unknown) => u is FiberFailure;Models
AsyncFiberException interface
Signature
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 interface
Signature
interface FiberFailure extends Error, Inspectable {
readonly [FiberFailureCauseId]: Cause<unknown>;
readonly [FiberFailureId]: typeof FiberFailureId;
}RunCallbackOptions interface
Signature
interface RunCallbackOptions<in A, in E = never> extends RunForkOptions {
readonly onExit?: (exit: Exit<A, E>) => void;
}RunForkOptions interface
Signature
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
disableRuntimeFlag
Signature
declare const disableRuntimeFlag: {
(flag: RuntimeFlag): <R>(self: Runtime<R>) => Runtime<R>;
<R>(self: Runtime<R>, flag: RuntimeFlag): Runtime<R>;
};enableRuntimeFlag
Signature
declare const enableRuntimeFlag: {
(flag: RuntimeFlag): <R>(self: Runtime<R>) => Runtime<R>;
<R>(self: Runtime<R>, flag: RuntimeFlag): Runtime<R>;
};updateRuntimeFlags
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
FiberFailureCauseId
Signature
declare const FiberFailureCauseId: unique symbol;FiberFailureId
Signature
declare const FiberFailureId: typeof FiberFailureId;FiberFailureId type
Signature
type FiberFailureId = typeof FiberFailureId;
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.