<E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): voidRepresents a teardown function that handles program completion and determines the exit code.
When to use
Use when integrating makeRunMain with a host platform that needs to
translate an Effect Exit into a process, worker, or application exit code.
Details
A teardown function is called when an Effect program completes, either
successfully or with a failure. It determines the appropriate exit code and
can perform cleanup before invoking the supplied onExit callback.
Example (Customizing teardown behavior)
import { Effect, Exit, Runtime } from "effect"
// Custom teardown that logs completion status
const customTeardown: Runtime.Teardown = (exit, onExit) => {
if (Exit.isSuccess(exit)) {
console.log("Program completed successfully with value:", exit.value)
onExit(0)
} else {
console.log("Program failed with cause:", exit.cause)
onExit(1)
}
}
// Use with makeRunMain
const runMain = Runtime.makeRunMain(({ fiber, teardown }) => {
fiber.addObserver((exit) => {
teardown(exit, (code) => {
console.log(`Exiting with code: ${code}`)
})
})
})
const program = Effect.succeed("Hello, World!")
runMain(program, { teardown: customTeardown })export interface Teardown {
<function (type parameter) E in <E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): voidE, function (type parameter) A in <E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): voidA>(exit: Exit.Exit<E, A>exit: import ExitExit.type Exit<A, E = never> = Exit.Success<A, E> | Exit.Failure<A, E>Represents the result of an Effect computation.
When to use
Use when you need to synchronously inspect whether an Effect computation
succeeded or failed.
Details
An Exit<A, E> is either Success<A, E> containing a value of type A, or
Failure<A, E> containing a Cause<E> describing why the computation
failed.
Since Exit is also an Effect, you can yield it inside Effect.gen.
Example (Pattern matching on an Exit)
import { Exit } from "effect"
const success: Exit.Exit<number> = Exit.succeed(42)
const failure: Exit.Exit<number, string> = Exit.fail("error")
const result = Exit.match(success, {
onSuccess: (value) => `Got value: ${value}`,
onFailure: (cause) => `Got error: ${cause}`
})
Namespace containing helper types shared by Exit values.
When to use
Use to reference helper types that describe the shared structure of Exit
values.
Exit<function (type parameter) E in <E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): voidE, function (type parameter) A in <E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): voidA>, onExit: (code: number) => voidonExit: (code: numbercode: number) => void): void
}