<R>(context: Context.Context<R>): <A, E>(effect: Effect<A, E, R>) => AExecutes 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) // 5export const const runSyncWith: <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
runSyncWith: <function (type parameter) R in <R>(context: Context.Context<R>): <A, E>(effect: Effect<A, E, R>) => AR>(
context: Context.Context<R>(parameter) context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context: import ContextContext.type Context.Context = /*unresolved*/ anyContext<function (type parameter) R in <R>(context: Context.Context<R>): <A, E>(effect: Effect<A, E, R>) => AR>
) => <function (type parameter) A in <A, E>(effect: Effect<A, E, R>): AA, function (type parameter) E in <A, E>(effect: Effect<A, E, R>): AE>(effect: Effect<A, E, R>(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, R>): AA, function (type parameter) E in <A, E>(effect: Effect<A, E, R>): AE, function (type parameter) R in <R>(context: Context.Context<R>): <A, E>(effect: Effect<A, E, R>) => AR>) => function (type parameter) A in <A, E>(effect: Effect<A, E, R>): AA = import internalinternal.const runSyncWith: <R>(
context: Context.Context<R>
) => <A, E>(effect: Effect.Effect<A, E, R>) => A
runSyncWith