Hyperlinkv0.8.0-beta.28

Effect

Effect.exitconsteffect/Effect.ts:2297
<A, E, R>(self: Effect<A, E, R>): Effect<Exit.Exit<A, E>, never, R>

Transforms an effect to encapsulate both failure and success using the Exit data type.

When to use

Use when you need to inspect the full outcome, including typed failures, defects, and interruptions.

Details

exit wraps an effect's success or failure inside an Exit type, allowing you to handle both cases explicitly.

The resulting effect cannot fail because the failure is encapsulated within the Exit.Failure type. The error type is set to never, indicating that the effect is structured to never fail directly.

Example (Capturing completion as Exit)

import { Effect } from "effect"

const success = Effect.succeed(42)
const failure = Effect.fail("Something went wrong")

const program1 = Effect.exit(success)
const program2 = Effect.exit(failure)

Effect.runPromise(program1).then(console.log)
// { _id: 'Exit', _tag: 'Success', value: 42 }

Effect.runPromise(program2).then(console.log)
// { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Something went wrong' } }
outcome encapsulationoptionresult
Source effect/Effect.ts:22973 lines
export const exit: <A, E, R>(
  self: Effect<A, E, R>
) => Effect<Exit.Exit<A, E>, never, R> = internal.exit
Referenced by 8 symbols