/** * @since 1.0.0 */ import type * as Context from "@effect/data/Context" import type { Pipeable } from "@effect/data/Pipeable" import type * as Effect from "@effect/io/Effect" import type * as ExecutionStrategy from "@effect/io/ExecutionStrategy" import type * as Exit from "@effect/io/Exit" import * as core from "@effect/io/internal/core" import * as fiberRuntime from "@effect/io/internal/fiberRuntime" /** * @since 1.0.0 * @category symbols */ export const ScopeTypeId: unique symbol = core.ScopeTypeId /** * @since 1.0.0 * @category symbols */ export type ScopeTypeId = typeof ScopeTypeId /** * @since 1.0.0 * @category symbols */ export const CloseableScopeTypeId: unique symbol = core.CloseableScopeTypeId /** * @since 1.0.0 * @category symbols */ export type CloseableScopeTypeId = typeof CloseableScopeTypeId /** * @since 1.0.0 * @category models */ export interface Scope extends Pipeable { readonly [ScopeTypeId]: ScopeTypeId readonly strategy: ExecutionStrategy.ExecutionStrategy /** * @internal */ readonly fork: (strategy: ExecutionStrategy.ExecutionStrategy) => Effect.Effect /** * @internal */ readonly addFinalizer: (finalizer: Scope.Finalizer) => Effect.Effect } /** * @since 1.0.0 * @category models */ export interface CloseableScope extends Scope, Pipeable { readonly [CloseableScopeTypeId]: CloseableScopeTypeId /** * @internal */ readonly close: (exit: Exit.Exit) => Effect.Effect } /** * @since 1.0.0 * @category context */ export const Scope: Context.Tag = fiberRuntime.scopeTag /** * @since 1.0.0 */ export declare namespace Scope { /** * @since 1.0.0 * @category model */ export type Finalizer = (exit: Exit.Exit) => Effect.Effect /** * @since 1.0.0 * @category model */ export type Closeable = CloseableScope } /** * Adds a finalizer to this scope. The finalizer is guaranteed to be run when * the scope is closed. * * @since 1.0.0 * @category utils */ export const addFinalizer: ( self: Scope, finalizer: Effect.Effect ) => Effect.Effect = core.scopeAddFinalizer /** * A simplified version of `addFinalizerWith` when the `finalizer` does not * depend on the `Exit` value that the scope is closed with. * * @since 1.0.0 * @category utils */ export const addFinalizerExit: (self: Scope, finalizer: Scope.Finalizer) => Effect.Effect = core.scopeAddFinalizerExit /** * Closes a scope with the specified exit value, running all finalizers that * have been added to the scope. * * @since 1.0.0 * @category destructors */ export const close: (self: CloseableScope, exit: Exit.Exit) => Effect.Effect = core.scopeClose /** * Extends the scope of an `Effect` workflow that needs a scope into this * scope by providing it to the workflow but not closing the scope when the * workflow completes execution. This allows extending a scoped value into a * larger scope. * * @since 1.0.0 * @category utils */ export const extend: { (scope: Scope): (effect: Effect.Effect) => Effect.Effect, E, A> (effect: Effect.Effect, scope: Scope): Effect.Effect, E, A> } = fiberRuntime.scopeExtend /** * Forks a new scope that is a child of this scope. The child scope will * automatically be closed when this scope is closed. * * @since 1.0.0 * @category utils */ export const fork: ( self: Scope, strategy: ExecutionStrategy.ExecutionStrategy ) => Effect.Effect = core.scopeFork /** * Uses the scope by providing it to an `Effect` workflow that needs a scope, * guaranteeing that the scope is closed with the result of that workflow as * soon as the workflow completes execution, whether by success, failure, or * interruption. * * @since 1.0.0 * @category destructors */ export const use: { (scope: CloseableScope): (effect: Effect.Effect) => Effect.Effect, E, A> (effect: Effect.Effect, scope: CloseableScope): Effect.Effect, E, A> } = fiberRuntime.scopeUse /** * Creates a Scope where Finalizers will run according to the `ExecutionStrategy`. * * If an ExecutionStrategy is not provided `sequential` will be used. * * @since 1.0.0 * @category constructors */ export const make: ( executionStrategy?: ExecutionStrategy.ExecutionStrategy ) => Effect.Effect = fiberRuntime.scopeMake