effect-io-ai

Package: effect
Module: Effect

Effect.runSyncWith

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

Signature

declare const runSyncWith: <R>(context: Context.Context<R>) => <A, E>(effect: Effect<A, E, R>) => A

Source

Since v4.0.0