Hyperlinkv0.8.0-beta.28

Effect

Effect.runPromiseWithconsteffect/Effect.ts:9059
<R>(context: Context.Context<R>): <A, E>(
  effect: Effect<A, E, R>,
  options?: RunOptions | undefined
) => Promise<A>

Executes an effect as a Promise with the provided services.

When to use

Use when you already have a Context and need Promise interop that rejects on effect failure.

Example (Running with services as a promise)

import { Context, Effect } from "effect"

interface Config {
  apiUrl: string
}

const Config = Context.Service<Config>("Config")

const context = Context.make(Config, {
  apiUrl: "https://api.example.com"
})

const program = Effect.gen(function*() {
  const config = yield* Config
  return `Connecting to ${config.apiUrl}`
})

Effect.runPromiseWith(context)(program).then(console.log)
running
Source effect/Effect.ts:90593 lines
export const runPromiseWith: <R>(
  context: Context.Context<R>
) => <A, E>(effect: Effect<A, E, R>, options?: RunOptions | undefined) => Promise<A> = internal.runPromiseWith
Referenced by 2 symbols