<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 })modelsmakeRunMain
Source effect/Runtime.ts:643 lines
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.Exit = /*unresolved*/ anyExit<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
}Referenced by 3 symbols