Hyperlinkv0.8.0-beta.28

Effect

Effect.runPromiseconsteffect/Effect.ts:9020
<A, E>(effect: Effect<A, E>, options?: RunOptions | undefined): Promise<A>

Executes an effect and returns the result as a Promise.

When to use

Use when you need to execute an effect and work with the result using Promise syntax, typically for compatibility with other promise-based code.

If the effect succeeds, the promise will resolve with the result. If the effect fails, the promise will reject with an error.

Example (Running a successful effect as a Promise)

import { Effect } from "effect"

Effect.runPromise(Effect.succeed(1)).then(console.log)
// Output: 1

Example (Running effects as promises)

//Example: Handling a Failing Effect as a Rejected Promise
import { Effect } from "effect"

Effect.runPromise(Effect.fail("my error")).catch(console.error)
// Output:
// (FiberFailure) Error: my error
Source effect/Effect.ts:90204 lines
export const runPromise: <A, E>(
  effect: Effect<A, E>,
  options?: RunOptions | undefined
) => Promise<A> = internal.runPromise
Referenced by 2 symbols