<A, E>(self: Scope, exit: Exit<A, E>): Effect<void>Closes a scope and runs its registered finalizers.
When to use
Use to close a scope manually with a specific exit value.
Details
Finalizers run in the scope's configured order and receive the supplied
Exit.
Example (Running scope finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const resourceManagement = Effect.gen(function*() {
const scope = yield* Scope.make("sequential")
// Add multiple finalizers
yield* Scope.addFinalizer(scope, Console.log("Close database connection"))
yield* Scope.addFinalizer(scope, Console.log("Close file handle"))
yield* Scope.addFinalizer(scope, Console.log("Release memory"))
// Do some work...
yield* Console.log("Performing operations...")
// Close scope - finalizers run in reverse order of registration
yield* Scope.close(scope, Exit.succeed("Success!"))
// Output: "Release memory", "Close file handle", "Close database connection"
})combinators
Source effect/Scope.ts:5201 lines
export const const close: <A, E>(
self: Scope,
exit: Exit<A, E>
) => Effect<void>
Closes a scope and runs its registered finalizers.
When to use
Use to close a scope manually with a specific exit value.
Details
Finalizers run in the scope's configured order and receive the supplied
Exit.
Example (Running scope finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const resourceManagement = Effect.gen(function*() {
const scope = yield* Scope.make("sequential")
// Add multiple finalizers
yield* Scope.addFinalizer(scope, Console.log("Close database connection"))
yield* Scope.addFinalizer(scope, Console.log("Close file handle"))
yield* Scope.addFinalizer(scope, Console.log("Release memory"))
// Do some work...
yield* Console.log("Performing operations...")
// Close scope - finalizers run in reverse order of registration
yield* Scope.close(scope, Exit.succeed("Success!"))
// Output: "Release memory", "Close file handle", "Close database connection"
})
close: <function (type parameter) A in <A, E>(self: Scope, exit: Exit<A, E>): Effect<void>A, function (type parameter) E in <A, E>(self: Scope, exit: Exit<A, E>): Effect<void>E>(self: Scope(parameter) self: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
self: Scope, exit: Exit<A, E>exit: import ExitExit<function (type parameter) A in <A, E>(self: Scope, exit: Exit<A, E>): Effect<void>A, function (type parameter) E in <A, E>(self: Scope, exit: Exit<A, E>): Effect<void>E>) => import EffectEffect<void> = import effecteffect.const scopeClose: <A, E>(
self: Scope.Scope,
exit_: Exit.Exit<A, E>
) => Effect.Effect<void, never, never>
scopeCloseReferenced by 25 symbols
Channel.catchCauseChannel.concatWithChannel.fromTransformBracketChannel.mergeChannel.mergeAllChannel.orElseIfEmptyLayer.fromBuildManagedRuntime.makePubSub.shutdownPubSub.subscribeRcMap.invalidateRcMap.makeScopedCache.entriesScopedCache.getScopedCache.invalidateScopedCache.invalidateWhenScopedCache.keysScopedCache.refreshScopedCache.setScopedRef.fromAcquireScopedRef.makeScopedRef.setStream.broadcastNStream.raceAllStream.toAsyncIterableWith