Hyperlinkv0.8.0-beta.28

Scope

Scope.provideconsteffect/Scope.ts:317
(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>
>

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)
})
combinators
Source effect/Scope.ts:3174 lines
export 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>>
} = effect.provideScope
Referenced by 12 symbols