<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: 1Example (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 errorexport const const runPromise: <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
runPromise: <function (type parameter) A in <A, E>(effect: Effect<A, E>, options?: RunOptions | undefined): Promise<A>A, function (type parameter) E in <A, E>(effect: Effect<A, E>, options?: RunOptions | undefined): Promise<A>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>, options?: RunOptions | undefined): Promise<A>A, function (type parameter) E in <A, E>(effect: Effect<A, E>, options?: RunOptions | undefined): Promise<A>E>,
options: RunOptions | undefinedoptions?: RunOptions | undefined
) => interface Promise<T>Represents the completion of an asynchronous operation
Promise<function (type parameter) A in <A, E>(effect: Effect<A, E>, options?: RunOptions | undefined): Promise<A>A> = import internalinternal.const runPromise: <A, E>(
effect: Effect.Effect<A, E>,
options?: Effect.RunOptions | undefined
) => Promise<A>
runPromise