<A, E>(effect: Effect<A, E>): Exit.Exit<A, E>Runs an effect synchronously and captures the outcome safely as an Exit type, which
represents the outcome (success or failure) of the effect.
When to use
Use to find out whether an effect succeeded or failed, including any defects, without dealing with asynchronous operations.
Details
The Exit type represents the result of the effect. Successful effects are
wrapped in Success, and failed effects are wrapped in Failure with a
Cause.
If the effect contains asynchronous operations, runSyncExit will
return an Failure with a Die cause, indicating that the effect cannot be
resolved synchronously.
Example (Observing synchronous results as Exit)
import { Effect } from "effect"
console.log(Effect.runSyncExit(Effect.succeed(1)))
// Output:
// {
// _id: "Exit",
// _tag: "Success",
// value: 1
// }
console.log(Effect.runSyncExit(Effect.fail("my error")))
// Output:
// {
// _id: "Exit",
// _tag: "Failure",
// cause: {
// _id: "Cause",
// _tag: "Fail",
// failure: "my error"
// }
// }Example (Capturing async work as a Die cause)
import { Effect } from "effect"
console.log(Effect.runSyncExit(Effect.promise(() => Promise.resolve(1))))
// Output:
// {
// _id: 'Exit',
// _tag: 'Failure',
// cause: {
// _id: 'Cause',
// _tag: 'Die',
// defect: [Fiber #0 cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work] {
// fiber: [FiberRuntime],
// _tag: 'AsyncFiberException',
// name: 'AsyncFiberException'
// }
// }
// }export const const runSyncExit: <A, E>(
effect: Effect<A, E>
) => Exit.Exit<A, E>
Runs an effect synchronously and captures the outcome safely as an Exit type, which
represents the outcome (success or failure) of the effect.
When to use
Use to find out whether an effect succeeded or failed,
including any defects, without dealing with asynchronous operations.
Details
The Exit type represents the result of the effect. Successful effects are
wrapped in Success, and failed effects are wrapped in Failure with a
Cause.
If the effect contains asynchronous operations, runSyncExit will
return an Failure with a Die cause, indicating that the effect cannot be
resolved synchronously.
Example (Observing synchronous results as Exit)
import { Effect } from "effect"
console.log(Effect.runSyncExit(Effect.succeed(1)))
// Output:
// {
// _id: "Exit",
// _tag: "Success",
// value: 1
// }
console.log(Effect.runSyncExit(Effect.fail("my error")))
// Output:
// {
// _id: "Exit",
// _tag: "Failure",
// cause: {
// _id: "Cause",
// _tag: "Fail",
// failure: "my error"
// }
// }
Example (Capturing async work as a Die cause)
import { Effect } from "effect"
console.log(Effect.runSyncExit(Effect.promise(() => Promise.resolve(1))))
// Output:
// {
// _id: 'Exit',
// _tag: 'Failure',
// cause: {
// _id: 'Cause',
// _tag: 'Die',
// defect: [Fiber #0 cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work] {
// fiber: [FiberRuntime],
// _tag: 'AsyncFiberException',
// name: 'AsyncFiberException'
// }
// }
// }
runSyncExit: <function (type parameter) A in <A, E>(effect: Effect<A, E>): Exit.Exit<A, E>A, function (type parameter) E in <A, E>(effect: Effect<A, E>): Exit.Exit<A, E>E>(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: 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 <A, E>(effect: Effect<A, E>): Exit.Exit<A, E>A, function (type parameter) E in <A, E>(effect: Effect<A, E>): Exit.Exit<A, E>E>) => 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) A in <A, E>(effect: Effect<A, E>): Exit.Exit<A, E>A, function (type parameter) E in <A, E>(effect: Effect<A, E>): Exit.Exit<A, E>E> = import internalinternal.const runSyncExit: <A, E>(
effect: Effect.Effect<A, E>
) => Exit.Exit<A, E>
runSyncExit