effect-io-ai

Package: effect
Module: Scope

Scope.provide

Provides a concrete Scope to an effect.

When to use

Use to run an effect that requires Scope with a scope managed by the caller.

Details

Providing the scope removes the Scope requirement from the effect context.

Example (Providing a scope)

import { Console, Effect, Scope } from "effect"

// An effect that requires a Scope
const program = Effect.gen(function*() {
  const scope = yield* Scope.Scope
  yield* Scope.addFinalizer(scope, Console.log("Cleanup"))
  yield* Console.log("Working...")
})

// Provide a scope to the program
const withScope = Effect.gen(function*() {
  const scope = yield* Scope.make()
  yield* Scope.provide(scope)(program)
})

Signature

declare const provide: { (value: Scope): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, Scope>>; <A, E, R>(self: Effect<A, E, R>, value: Scope): Effect<A, E, Exclude<R, Scope>>; }

Source

Since v4.0.0