import "../Operator/index.js"; import type { UIO } from "../Effect/effect.js"; import * as E from "../Either/index.js"; import { AtomicNumber } from "../Support/AtomicNumber/index.js"; import { AtomicReference } from "../Support/AtomicReference/index.js"; /** * Represent Common Ops between Global | Local */ export interface CommonScope { /** * Determines if the scope is closed at the instant the effect executes. * Returns an effect that will succeed with `true` if the scope is closed, * and `false` otherwise. */ readonly closed: UIO; /** * Prevents a previously added finalizer from being executed when the scope * is closed. The returned effect will succeed with `true` if the finalizer * will not be run by this scope, and `false` otherwise. */ readonly deny: (key: Key) => UIO; /** * Determines if the scope is empty (has no finalizers) at the instant the * effect executes. The returned effect will succeed with `true` if the scope * is empty, and `false` otherwise. */ readonly empty: UIO; /** * Adds a finalizer to the scope. If successful, this ensures that when the * scope exits, the finalizer will be run * * The returned effect will succeed with a key if the finalizer was added * to the scope, and `None` if the scope is already closed. */ readonly ensure: (finalizer: (a: A) => UIO) => UIO>; /** * Extends the specified scope so that it will not be closed until this * scope is closed. Note that extending a scope into the global scope * will result in the scope *never* being closed! * * Scope extension does not result in changes to the scope contract: open * scopes must *always* be closed. */ readonly extend: (that: Scope) => UIO; /** * Determines if the scope is open at the moment the effect is executed. * Returns an effect that will succeed with `true` if the scope is open, * and `false` otherwise. */ readonly open: UIO; /** * Determines if the scope has been released at the moment the effect is * executed. A scope can be closed yet unreleased, if it has been * extended by another scope which is not yet released. */ readonly released: UIO; readonly unsafeEnsure: (finalizer: (_: A) => UIO) => E.Either; readonly unsafeExtend: (that: Scope) => boolean; readonly unsafeDeny: (key: Key) => boolean; } /** * Represents a key in a scope, which is associated with a single finalizer. */ export declare class Key { /** * Attempts to remove the finalizer associated with this key from the * scope. The returned effect will succeed with a boolean, which indicates * whether the attempt was successful. A value of `true` indicates the * finalizer will not be executed, while a value of `false` indicates the * finalizer was already executed. */ remove: UIO; constructor(remove?: UIO); setRemove(remove: UIO): void; } /** * A `Scope` is a value that allows adding finalizers identified by a key. * Scopes are closed with a value of type `A`, which is provided to all the * finalizers when the scope is released. * * For safety reasons, this interface has no method to close a scope. Rather, * an open scope may be required with `makeScope`, which returns a function * that can close a scope. This allows scopes to be safely passed around * without fear they will be accidentally closed. */ export declare type Scope = Global | Local; /** * The global scope, which is entirely stateless. Finalizers added to the * global scope will never be executed (nor kept in memory). */ export declare class Global implements CommonScope { readonly _tag = "Global"; constructor(); private unsafeEnsureResult; private ensureResult; get closed(): UIO; deny(_key: Key): UIO; get empty(): UIO; ensure(_finalizer: (a: never) => UIO): UIO>; extend(that: Scope): UIO; get open(): UIO; get released(): UIO; unsafeEnsure(_finalizer: (_: never) => UIO): E.Either; unsafeExtend(that: Scope): boolean; unsafeDeny(): boolean; } export declare class OrderedFinalizer { readonly order: number; readonly finalizer: (_: any) => UIO; constructor(order: number, finalizer: (_: any) => UIO); } export declare class Local implements CommonScope { readonly finalizerCount: AtomicNumber; readonly exitValue: AtomicReference; readonly references: AtomicNumber; readonly finalizers: Map; readonly _tag = "Local"; constructor(finalizerCount: AtomicNumber, exitValue: AtomicReference, references: AtomicNumber, finalizers: Map); get closed(): UIO; get open(): UIO; deny(key: Key): UIO; get empty(): UIO; ensure(finalizer: (a: A) => UIO): UIO>; extend(that: Scope): UIO; get released(): UIO; unsafeExtend(that: Scope): boolean; get release(): UIO; unsafeReleased(): boolean; unsafeEnsure(finalizer: (_: A) => UIO): E.Either; unsafeAddRef(): boolean; get unsafeClosed(): boolean; unsafeDeny(key: Key): boolean; unsafeClose(a: A): UIO | null; unsafeRelease(): UIO | null; get unsafeEmpty(): boolean; } /** * The global scope, which is entirely stateless. Finalizers added to the * global scope will never be executed (nor kept in memory). */ export declare const globalScope: Global; /** * A tuple that contains an open scope, together with a function that closes * the scope. */ export declare class Open { readonly close: (_: A) => UIO; readonly scope: Local; constructor(close: (_: A) => UIO, scope: Local); } export declare function unsafeMakeScope(): Open; export declare function makeScope(): UIO>; //# sourceMappingURL=index.d.ts.map