Scope.ts overview
Since v2.0.0
Exports Grouped by Category
constructors
make
Creates a new closeable scope where finalizers will run according to the specified ExecutionStrategy
. If no execution strategy is provided, sequential
will be used by default.
Signature
declare const make: (executionStrategy?: ExecutionStrategy.ExecutionStrategy) => Effect.Effect<CloseableScope>
Since v2.0.0
context
Scope
A tag representing the current Scope
in the environment.
Signature
declare const Scope: Context.Tag<Scope, Scope>
Since v2.0.0
destructors
close
Closes this scope with the specified exit value, running all finalizers that have been added to the scope.
Signature
declare const close: (self: CloseableScope, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void>
Since v2.0.0
use
Provides this closeable scope to an Effect
that requires a scope, guaranteeing that the scope is closed with the result of that effect as soon as the effect completes execution, whether by success, failure, or interruption.
Signature
declare const use: {
(scope: CloseableScope): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Scope>>
<A, E, R>(effect: Effect.Effect<A, E, R>, scope: CloseableScope): Effect.Effect<A, E, Exclude<R, Scope>>
}
Since v2.0.0
models
CloseableScope (interface)
A scope that can be explicitly closed with a specified exit value.
Signature
export interface CloseableScope extends Scope, Pipeable {
readonly [CloseableScopeTypeId]: CloseableScopeTypeId
/**
* Closes this scope with the given exit value, running all finalizers.
*
* @internal
*/
close(exit: Exit.Exit<unknown, unknown>): Effect.Effect<void>
}
Since v2.0.0
Scope (interface)
Represents a scope that manages finalizers and can fork child scopes.
Signature
export interface Scope extends Pipeable {
readonly [ScopeTypeId]: ScopeTypeId
/**
* The execution strategy for running finalizers in this scope.
*/
readonly strategy: ExecutionStrategy.ExecutionStrategy
/**
* Forks a new child scope with the specified execution strategy. The child scope
* will automatically be closed when this scope is closed.
*
* @internal
*/
fork(strategy: ExecutionStrategy.ExecutionStrategy): Effect.Effect<Scope.Closeable>
/**
* Adds a finalizer to this scope. The finalizer will be run when the scope is closed.
*
* @internal
*/
addFinalizer(finalizer: Scope.Finalizer): Effect.Effect<void>
}
Since v2.0.0
symbols
CloseableScopeTypeId
A unique identifier for the CloseableScope
type.
Signature
declare const CloseableScopeTypeId: unique symbol
Since v2.0.0
CloseableScopeTypeId (type alias)
The type of the unique identifier for CloseableScope
.
Signature
type CloseableScopeTypeId = typeof CloseableScopeTypeId
Since v2.0.0
ScopeTypeId
A unique identifier for the Scope
type.
Signature
declare const ScopeTypeId: unique symbol
Since v2.0.0
ScopeTypeId (type alias)
The type of the unique identifier for Scope
.
Signature
type ScopeTypeId = typeof ScopeTypeId
Since v2.0.0
utils
Scope (namespace)
Since v2.0.0
Finalizer (type alias)
A finalizer function that takes an Exit
value and returns an Effect
.
Signature
type Finalizer = (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void>
Since v2.0.0
Closeable (type alias)
A closeable scope that can be explicitly closed.
Signature
type Closeable = CloseableScope
Since v2.0.0
addFinalizer
Adds a finalizer to this scope. The finalizer is guaranteed to be run when the scope is closed. Use this when the finalizer does not need to know the Exit
value that the scope is closed with.
See
addFinalizerExit
Signature
declare const addFinalizer: (self: Scope, finalizer: Effect.Effect<unknown>) => Effect.Effect<void>
Since v2.0.0
addFinalizerExit
Adds a finalizer to this scope. The finalizer receives the Exit
value when the scope is closed, allowing it to perform different actions based on the exit status.
See
addFinalizer
Signature
declare const addFinalizerExit: (self: Scope, finalizer: Scope.Finalizer) => Effect.Effect<void>
Since v2.0.0
extend
Extends the scope of an Effect
that requires a scope into this scope. It provides this scope to the effect but does not close the scope when the effect completes execution. This allows extending a scoped value into a larger scope.
Signature
declare const extend: {
(scope: Scope): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Scope>>
<A, E, R>(effect: Effect.Effect<A, E, R>, scope: Scope): Effect.Effect<A, E, Exclude<R, Scope>>
}
Since v2.0.0
fork
Forks a new child scope with the specified execution strategy. The child scope will automatically be closed when this scope is closed.
Signature
declare const fork: (self: Scope, strategy: ExecutionStrategy.ExecutionStrategy) => Effect.Effect<CloseableScope>
Since v2.0.0