(scope: Scope, finalizer: Effect<unknown>): Effect<void>Registers a finalizer effect on a scope.
Details
If the scope is open, the finalizer runs when the scope closes, regardless of whether the scope closes successfully or with an error. If the scope is already closed, the finalizer runs immediately.
Example (Adding finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const scope = yield* Scope.make()
// Add simple finalizers
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 1"))
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 2"))
yield* Scope.addFinalizer(scope, Effect.log("Cleanup task 3"))
// Do some work
yield* Console.log("Doing work...")
// Close the scope
yield* Scope.close(scope, Exit.void)
})combinators
Source effect/Scope.ts:4021 lines
export const const addFinalizer: (
scope: Scope,
finalizer: Effect<unknown>
) => Effect<void>
Registers a finalizer effect on a scope.
Details
If the scope is open, the finalizer runs when the scope closes, regardless of
whether the scope closes successfully or with an error. If the scope is
already closed, the finalizer runs immediately.
Example (Adding finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const scope = yield* Scope.make()
// Add simple finalizers
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 1"))
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 2"))
yield* Scope.addFinalizer(scope, Effect.log("Cleanup task 3"))
// Do some work
yield* Console.log("Doing work...")
// Close the scope
yield* Scope.close(scope, Exit.void)
})
addFinalizer: (scope: Scope(parameter) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope: Scope, finalizer: Effect<unknown>(parameter) finalizer: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
finalizer: import EffectEffect<unknown>) => import EffectEffect<void> = import effecteffect.const scopeAddFinalizer: (
scope: Scope.Scope,
finalizer: Effect.Effect<unknown>
) => Effect.Effect<void>
scopeAddFinalizerReferenced by 15 symbols
Channel.bufferChannel.bufferArrayChannel.fromAsyncIterableChannel.mergeChannel.mergeAllChannel.toQueueChannel.toQueueArrayPool.makeWithStrategyPubSub.subscribeRcMap.getScopedCache.makeWithStream.fromReadableStreamNodeHttpServer.make (platform-node)NodeWorker.layerPlatform (platform-node)SqliteClient.make (sql-sqlite-node)