(
f: <E, A>(options: {
readonly fiber: Fiber.Fiber<A, E>
readonly teardown: Teardown
}) => void
): {
(options?: {
readonly disableErrorReporting?: boolean | undefined
readonly teardown?: Teardown | undefined
}): <E, A>(effect: Effect.Effect<A, E>) => void
<E, A>(
effect: Effect.Effect<A, E>,
options?: {
readonly disableErrorReporting?: boolean | undefined
readonly teardown?: Teardown | undefined
}
): void
}Creates a platform-specific main program runner that handles Effect execution lifecycle.
When to use
Use when building a runtime adapter for a host platform.
Details
The runner executes Effect programs as main entry points. The provided function receives a forked fiber and a teardown callback so it can install platform-specific signal handling, fiber observers, and final exit behavior.
Most applications should use a platform-provided runner, such as
NodeRuntime.runMain, rather than constructing one directly.
disableErrorReporting disables the automatic log emitted for unreported
non-interruption failures. It does not change exit-code calculation or the
custom teardown callback.
Gotchas
The setup function is responsible for observing the fiber and eventually
invoking teardown. makeRunMain also tries to keep the host process alive
with a long interval while the main fiber is running; if the host blocks
timers, the runner still starts but cannot use that keep-alive fallback.
Example (Creating platform runners)
import { Effect, Fiber, Runtime } from "effect"
// Create a simple runner for a hypothetical platform
const runMain = Runtime.makeRunMain(({ fiber, teardown }) => {
// Set up signal handling
const handleSignal = () => {
Effect.runSync(Fiber.interrupt(fiber))
}
// Add signal listeners (platform-specific)
// process.on('SIGINT', handleSignal)
// process.on('SIGTERM', handleSignal)
// Handle fiber completion
fiber.addObserver((exit) => {
teardown(exit, (code) => {
console.log(`Program finished with exit code: ${code}`)
// process.exit(code)
})
})
})
// Use the runner
const program = Effect.gen(function*() {
yield* Effect.log("Starting program")
yield* Effect.sleep(1000)
yield* Effect.log("Program completed")
return "success"
})
// Run with default options
runMain(program)
// Run with custom teardown
runMain(program, {
teardown: (exit, onExit) => {
console.log("Custom teardown logic")
Runtime.defaultTeardown(exit, onExit)
}
})export const const makeRunMain: (
f: <E, A>(options: {
readonly fiber: Fiber.Fiber<A, E>
readonly teardown: Teardown
}) => void
) => {
(options?: {
readonly disableErrorReporting?:
| boolean
| undefined
readonly teardown?: Teardown | undefined
}): <E, A>(effect: Effect.Effect<A, E>) => void
<E, A>(
effect: Effect.Effect<A, E>,
options?: {
readonly disableErrorReporting?:
| boolean
| undefined
readonly teardown?: Teardown | undefined
}
): void
}
Creates a platform-specific main program runner that handles Effect execution lifecycle.
When to use
Use when building a runtime adapter for a host platform.
Details
The runner executes Effect programs as main entry points. The provided
function receives a forked fiber and a teardown callback so it can install
platform-specific signal handling, fiber observers, and final exit behavior.
Most applications should use a platform-provided runner, such as
NodeRuntime.runMain, rather than constructing one directly.
disableErrorReporting disables the automatic log emitted for unreported
non-interruption failures. It does not change exit-code calculation or the
custom teardown callback.
Gotchas
The setup function is responsible for observing the fiber and eventually
invoking teardown. makeRunMain also tries to keep the host process alive
with a long interval while the main fiber is running; if the host blocks
timers, the runner still starts but cannot use that keep-alive fallback.
Example (Creating platform runners)
import { Effect, Fiber, Runtime } from "effect"
// Create a simple runner for a hypothetical platform
const runMain = Runtime.makeRunMain(({ fiber, teardown }) => {
// Set up signal handling
const handleSignal = () => {
Effect.runSync(Fiber.interrupt(fiber))
}
// Add signal listeners (platform-specific)
// process.on('SIGINT', handleSignal)
// process.on('SIGTERM', handleSignal)
// Handle fiber completion
fiber.addObserver((exit) => {
teardown(exit, (code) => {
console.log(`Program finished with exit code: ${code}`)
// process.exit(code)
})
})
})
// Use the runner
const program = Effect.gen(function*() {
yield* Effect.log("Starting program")
yield* Effect.sleep(1000)
yield* Effect.log("Program completed")
return "success"
})
// Run with default options
runMain(program)
// Run with custom teardown
runMain(program, {
teardown: (exit, onExit) => {
console.log("Custom teardown logic")
Runtime.defaultTeardown(exit, onExit)
}
})
makeRunMain = (
f: <E, A>(options: {
readonly fiber: Fiber.Fiber<A, E>
readonly teardown: Teardown
}) => void
f: <function (type parameter) E in <E, A>(options: {
readonly fiber: Fiber.Fiber<A, E>;
readonly teardown: Teardown;
}): void
E, function (type parameter) A in <E, A>(options: {
readonly fiber: Fiber.Fiber<A, E>;
readonly teardown: Teardown;
}): void
A>(
options: {
readonly fiber: Fiber.Fiber<A, E>
readonly teardown: Teardown
}
options: {
readonly fiber: Fiber.Fiber<A, E>(property) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
fiber: import FiberFiber.interface Fiber<out A, out E = never>A runtime fiber is a lightweight thread that executes Effects. Fibers are
the unit of concurrency in Effect. They provide a way to run multiple
Effects concurrently while maintaining structured concurrency and
cancellation safety.
When to use
Use to observe, join, interrupt, or coordinate work that has already been
forked.
Details
A fiber exposes both safe Effect-based operations, such as
await
,
join
, and
interrupt
, and low-level runtime fields used by
the scheduler and runtime internals.
Gotchas
Prefer the exported functions in this module over calling interruptUnsafe
or pollUnsafe directly. The unsafe methods are immediate runtime hooks and
do not provide the same Effect-based sequencing guarantees.
Example (Awaiting a forked fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Fork an effect to run in a new fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Wait for the fiber to complete and get its result
const result = yield* Fiber.await(fiber)
console.log(result) // Exit.succeed(42)
return result
})
The Fiber namespace contains utility types and functions for working with fibers.
It provides type-level utilities for fiber operations and variance encoding.
When to use
Use to reference type-level helpers associated with Fiber.
Details
The namespace currently exposes type-level support used by the Fiber
interface. Runtime operations are exported as module-level functions.
Example (Working with fiber types)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Use namespace types for variance
const typedFiber: Fiber.Fiber<number, never> = fiber
// Access fiber properties
console.log(`Fiber ID: ${fiber.id}`)
// Join the fiber
const result = yield* Fiber.join(fiber)
return result // 42
})
Fiber<function (type parameter) A in <E, A>(options: {
readonly fiber: Fiber.Fiber<A, E>;
readonly teardown: Teardown;
}): void
A, function (type parameter) E in <E, A>(options: {
readonly fiber: Fiber.Fiber<A, E>;
readonly teardown: Teardown;
}): void
E>
readonly teardown: Teardownteardown: Teardown
}
) => void
): {
(
options: {
readonly disableErrorReporting?:
| boolean
| undefined
readonly teardown?: Teardown | undefined
}
options?: {
readonly disableErrorReporting?: boolean | undefineddisableErrorReporting?: boolean | undefined
readonly teardown?: Teardown | undefinedteardown?: Teardown | undefined
}
): <function (type parameter) E in <E, A>(effect: Effect.Effect<A, E>): voidE, function (type parameter) A in <E, A>(effect: Effect.Effect<A, E>): voidA>(effect: Effect.Effect<A, E>(parameter) effect: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
effect: import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <E, A>(effect: Effect.Effect<A, E>): voidA, function (type parameter) E in <E, A>(effect: Effect.Effect<A, E>): voidE>) => void
<function (type parameter) E in <E, A>(effect: Effect.Effect<A, E>, options?: {
readonly disableErrorReporting?: boolean | undefined;
readonly teardown?: Teardown | undefined;
}): void
E, function (type parameter) A in <E, A>(effect: Effect.Effect<A, E>, options?: {
readonly disableErrorReporting?: boolean | undefined;
readonly teardown?: Teardown | undefined;
}): void
A>(
effect: Effect.Effect<A, E>(parameter) effect: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
effect: import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <E, A>(effect: Effect.Effect<A, E>, options?: {
readonly disableErrorReporting?: boolean | undefined;
readonly teardown?: Teardown | undefined;
}): void
A, function (type parameter) E in <E, A>(effect: Effect.Effect<A, E>, options?: {
readonly disableErrorReporting?: boolean | undefined;
readonly teardown?: Teardown | undefined;
}): void
E>,
options: {
readonly disableErrorReporting?:
| boolean
| undefined
readonly teardown?: Teardown | undefined
}
options?: {
readonly disableErrorReporting?: boolean | undefineddisableErrorReporting?: boolean | undefined
readonly teardown?: Teardown | undefinedteardown?: Teardown | undefined
}
): void
} =>
dual<(...args: Array<any>) => any, (effect: Effect.Effect<any, any>, options?: {
readonly disableErrorReporting?: boolean | undefined;
readonly teardown?: Teardown | undefined;
}) => void>(isDataFirst: (args: IArguments) => boolean, body: (effect: Effect.Effect<any, any>, options?: {
readonly disableErrorReporting?: boolean | undefined;
readonly teardown?: Teardown | undefined;
}) => void): ((...args: Array<any>) => any) & ((effect: Effect.Effect<any, any>, options?: {
readonly disableErrorReporting?: boolean | undefined;
readonly teardown?: Teardown | undefined;
}) => void) (+1 overload)
Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual((args: IArgumentsargs) => import EffectEffect.const isEffect: (
u: unknown
) => u is Effect<any, any, any>
Checks whether a value is an Effect.
Example (Checking whether a value is an Effect)
import { Effect } from "effect"
console.log(Effect.isEffect(Effect.succeed(1))) // true
console.log(Effect.isEffect("hello")) // false
isEffect(args: IArgumentsargs[0]), (effect: Effect.Effect<any, any>(parameter) effect: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
effect: import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<any, any>, options: {
readonly disableErrorReporting?:
| boolean
| undefined
readonly teardown?: Teardown | undefined
}
options?: {
readonly disableErrorReporting?: boolean | undefineddisableErrorReporting?: boolean | undefined
readonly teardown?: Teardown | undefinedteardown?: Teardown | undefined
}) => {
const const fiber: Fiber.Fiber<any, any>const fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
fiber = options: {
readonly disableErrorReporting?:
| boolean
| undefined
readonly teardown?: Teardown | undefined
}
options?.disableErrorReporting?: boolean | undefineddisableErrorReporting === true
? import EffectEffect.const runFork: <A, E>(
effect: Effect<A, E, never>,
options?: RunOptions | undefined
) => Fiber<A, E>
Runs an effect in the background, returning a fiber that can
be observed or interrupted.
When to use
Use when you need to start an effect in the background and receive a fiber.
Example (Running an effect in the background)
import { Console, Effect, Fiber, Schedule } from "effect"
// ┌─── Effect<number, never, never>
// ▼
const program = Effect.repeat(
Console.log("running..."),
Schedule.spaced("200 millis")
)
// ┌─── RuntimeFiber<number, never>
// ▼
const fiber = Effect.runFork(program)
setTimeout(() => {
Effect.runFork(Fiber.interrupt(fiber))
}, 500)
runFork(effect: Effect.Effect<any, any>(parameter) effect: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
effect)
: import EffectEffect.const runFork: <A, E>(
effect: Effect<A, E, never>,
options?: RunOptions | undefined
) => Fiber<A, E>
Runs an effect in the background, returning a fiber that can
be observed or interrupted.
When to use
Use when you need to start an effect in the background and receive a fiber.
Example (Running an effect in the background)
import { Console, Effect, Fiber, Schedule } from "effect"
// ┌─── Effect<number, never, never>
// ▼
const program = Effect.repeat(
Console.log("running..."),
Schedule.spaced("200 millis")
)
// ┌─── RuntimeFiber<number, never>
// ▼
const fiber = Effect.runFork(program)
setTimeout(() => {
Effect.runFork(Fiber.interrupt(fiber))
}, 500)
runFork(
import EffectEffect.const tapCause: {
<E, X, E2, R2>(
f: (
cause: Cause.Cause<NoInfer<E>>
) => Effect<X, E2, R2>
): <A, R>(
self: Effect<A, E, R>
) => Effect<A, E | E2, R2 | R>
<A, E, R, X, E2, R2>(
self: Effect<A, E, R>,
f: (
cause: Cause.Cause<E>
) => Effect<X, E2, R2>
): Effect<A, E | E2, R | R2>
}
tapCause(effect: Effect.Effect<any, any>(parameter) effect: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
effect, (cause: Cause.Cause<any>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause) => {
if (import CauseCause.const hasInterruptsOnly: <E>(
self: Cause<E>
) => boolean
Returns true if every reason in the cause is an Interrupt (and
there is at least one reason).
When to use
Use when you need to detect failures caused only by interruption.
Example (Checking interrupt-only causes)
import { Cause } from "effect"
console.log(Cause.hasInterruptsOnly(Cause.interrupt(123))) // true
console.log(Cause.hasInterruptsOnly(Cause.fail("error"))) // false
console.log(Cause.hasInterruptsOnly(Cause.empty)) // false
hasInterruptsOnly(cause: Cause.Cause<any>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause)) return import EffectEffect.const void: Effect.Effect<void, never, never>(alias) const void: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Returns an effect that succeeds with void.
void
const const isReported: booleanisReported = const getErrorReported: (
u: unknown
) => boolean
Reads the runtime error-reporting marker from an unknown error value.
When to use
Use to read whether an unknown error value should be treated as already
reported by the default main runner.
Details
Returns a boolean [Runtime.errorReported] property when it is present on an
object. Otherwise returns true, so failures are logged by default.
Gotchas
Non-object values, missing markers, and non-boolean marker values all return
true.
getErrorReported(import CauseCause.const squash: <E>(
self: Cause<E>
) => unknown
Collapses a Cause into a single unknown value, picking the "most
important" failure in this order:
When to use
Use to collapse a structured cause to the single value that synchronous and
promise runners would throw.
Details
- First
Fail error (the E value)
- First
Die defect
- A generic
Error("All fibers interrupted without error") for interrupt-only causes
- A generic
Error("Empty cause") for empty
This is the function used by Effect.runPromise and Effect.runSync to
decide what to throw.
Gotchas
This function is lossy. Use
prettyErrors
or iterate cause.reasons
when you need all failures.
Example (Squashing a cause)
import { Cause } from "effect"
console.log(Cause.squash(Cause.fail("error"))) // "error"
console.log(Cause.squash(Cause.die("defect"))) // "defect"
squash(cause: Cause.Cause<any>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause))
return const isReported: booleanisReported ? import EffectEffect.const logError: (
...message: ReadonlyArray<any>
) => Effect<void>
Logs one or more messages at the ERROR level.
Example (Logging errors)
import { Effect } from "effect"
const program = Effect.gen(function*() {
yield* Effect.logError("Database connection failed")
yield* Effect.logError(
"Error code:",
500,
"Message:",
"Internal server error"
)
// Can be used with error objects
const error = new Error("Something went wrong")
yield* Effect.logError("Caught error:", error.message)
})
Effect.runPromise(program)
// Output:
// timestamp=2023-... level=ERROR message="Database connection failed"
// timestamp=2023-... level=ERROR message="Error code: 500 Message: Internal server error"
// timestamp=2023-... level=ERROR message="Caught error: Something went wrong"
logError(cause: Cause.Cause<any>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause) : import EffectEffect.const void: Effect.Effect<void, never, never>(alias) const void: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Returns an effect that succeeds with void.
void
})
)
try {
const const keepAlive: numberkeepAlive = module globalThisglobalThis.function setInterval(
handler: TimerHandler,
timeout?: number,
...arguments: any[]
): number
setInterval(const constVoid: LazyArg<void>Returns no meaningful value when called.
When to use
Use when you need a thunk that is called only for its effect and has no
meaningful return value.
Example (Returning void from a thunk)
import { Function } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(Function.constVoid(), undefined)
constVoid, 2_147_483_647)
const fiber: Fiber.Fiber<any, any>const fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
fiber.Fiber<any, any>.addObserver: (cb: (exit: Exit<A, E>) => void) => () => voidaddObserver(() => {
function clearInterval(
id: number | undefined
): void
clearInterval(const keepAlive: numberkeepAlive)
})
} catch {}
const const teardown: Teardownteardown = options: {
readonly disableErrorReporting?:
| boolean
| undefined
readonly teardown?: Teardown | undefined
}
options?.teardown?: Teardown | undefinedteardown ?? const defaultTeardown: TeardownThe default teardown function that determines exit codes from an Effect exit.
When to use
Use as the standard teardown for main programs with conventional process
exit codes and support for
errorExitCode
.
Details
This teardown follows these exit-code rules:
0 for successful completion.
130 for interruption-only failures.
- The squashed error's
errorExitCode
value for other failures when
present.
1 for other failures.
Gotchas
The 130 code is used only when the Cause contains interruptions and no
other failure reasons. Mixed causes use the squashed error path instead.
Example (Referencing default teardown)
import { Exit, Runtime } from "effect"
const logExitCode = (exit: Exit.Exit<any, any>) => {
Runtime.defaultTeardown(exit, (code) => {
console.log(`Exit code: ${code}`)
})
}
logExitCode(Exit.succeed(42))
// Output: Exit code: 0
logExitCode(Exit.fail("error"))
// Output: Exit code: 1
logExitCode(Exit.interrupt(123))
// Output: Exit code: 130
defaultTeardown
return f: <E, A>(options: {
readonly fiber: Fiber.Fiber<A, E>
readonly teardown: Teardown
}) => void
f({ fiber: Fiber.Fiber<any, any>(property) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
fiber, teardown: Teardownteardown })
})