Hyperlinkv0.8.0-beta.28

Effect

Effect.runSyncWithconsteffect/Effect.ts:9256
<R>(context: Context.Context<R>): <A, E>(effect: Effect<A, E, R>) => A

Executes an effect synchronously with provided services.

When to use

Use when you already have a Context, the effect is known to complete synchronously, and failures should throw.

Example (Running synchronously with services)

import { Context, Effect } from "effect"

interface MathService {
  add: (a: number, b: number) => number
}

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

const context = Context.make(MathService, {
  add: (a, b) => a + b
})

const program = Effect.gen(function*() {
  const math = yield* MathService
  return math.add(2, 3)
})

const result = Effect.runSyncWith(context)(program)
console.log(result) // 5
running
Source effect/Effect.ts:92563 lines
export const runSyncWith: <R>(
  context: Context.Context<R>
) => <A, E>(effect: Effect<A, E, R>) => A = internal.runSyncWith
Referenced by 1 symbols