Hyperlinkv0.8.0-beta.28

Runtime

Runtime.Teardowninterfaceeffect/Runtime.ts:64
<E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): void

Represents 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 })
Source effect/Runtime.ts:643 lines
export interface Teardown {
  <E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void): void
}
Referenced by 3 symbols