Package: effect
Module: Scope
Creates a closeable child scope registered with a parent scope.
Details
Closing the parent closes the child with the same exit value, and closing the
child detaches it from the parent. The optional finalizer strategy configures
the child scope and defaults to "sequential" when omitted.
Example (Creating a child scope)
import { Console, Effect, Exit, Scope } from "effect"
const nestedScopes = Effect.gen(function*() {
const parentScope = yield* Scope.make("sequential")
// Add finalizer to parent
yield* Scope.addFinalizer(parentScope, Console.log("Parent cleanup"))
// Create child scope
const childScope = yield* Scope.fork(parentScope, "parallel")
// Add finalizer to child
yield* Scope.addFinalizer(childScope, Console.log("Child cleanup"))
// Close child first, then parent
yield* Scope.close(childScope, Exit.void)
yield* Scope.close(parentScope, Exit.void)
})
Signature
declare const fork: (scope: Scope, finalizerStrategy?: "sequential" | "parallel") => Effect<Closeable>
Since v2.0.0