(
scope: Scope,
finalizerStrategy?: "sequential" | "parallel"
): Effect<Closeable>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)
})combinators
Source effect/Scope.ts:4394 lines
export const const fork: (
scope: Scope,
finalizerStrategy?: "sequential" | "parallel"
) => Effect<Closeable>
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)
})
fork: (
scope: Scope(parameter) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope: Scope,
finalizerStrategy: "sequential" | "parallel" | undefinedfinalizerStrategy?: "sequential" | "parallel"
) => import EffectEffect<Closeable> = import effecteffect.const scopeFork: (
scope: Scope.Scope,
finalizerStrategy?: "sequential" | "parallel"
) => Effect.Effect<Scope.Closeable, never, never>
scopeFork