import type { Either } from "../../Either"; import * as E from "../../Either"; import { AtomicNumber, AtomicReference } from "../../support"; import type { IO } from "../Task"; /** * 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: IO; constructor(remove?: IO); setRemove(remove: IO): void; } /** * Represent Common Ops between Global | Local */ export interface CommonScope { /** * Determines if the scope is closed at the instant the effect executes. * Returns a task that will succeed with `true` if the scope is closed, * and `false` otherwise. */ readonly closed: IO; /** * 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) => IO; /** * 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: IO; /** * 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 ifthe finalizer was added * to the scope, and `None` if the scope is already closed. */ readonly ensure: (finalizer: (a: A) => IO) => IO>; /** * 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) => IO; /** * Determines if the scope is open at the moment the effect is executed. * Returns a task that will succeed with `true` if the scope is open, * and `false` otherwise. */ readonly open: IO; /** * 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: IO; readonly unsafeEnsure: (finalizer: (_: A) => IO) => Either; readonly unsafeExtend: (that: Scope) => boolean; readonly unsafeDeny: (key: Key) => boolean; } /** * 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 = GlobalScope | LocalScope; /** * The global scope, which is entirely stateless. Finalizers added to the * global scope will never be executed (nor kept in memory). */ export declare class GlobalScope implements CommonScope { readonly _tag = "Global"; constructor(); private unsafeEnsureResult; private ensureResult; get closed(): IO; deny(_key: Key): IO; get empty(): IO; ensure(_finalizer: (a: never) => IO): IO>; extend(that: Scope): IO; get open(): IO; get released(): IO; unsafeEnsure(_finalizer: (_: never) => IO): E.Either; unsafeExtend(that: Scope): boolean; unsafeDeny(): boolean; } export declare class OrderedFinalizer { readonly order: number; readonly finalizer: (_: any) => IO; constructor(order: number, finalizer: (_: any) => IO); } export declare class LocalScope 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(): IO; get open(): IO; deny(key: Key): IO; get empty(): IO; ensure(finalizer: (a: A) => IO): IO>; extend(that: Scope): IO; get released(): IO; unsafeExtend(that: Scope): boolean; get release(): IO; unsafeReleased(): boolean; unsafeEnsure(finalizer: (_: A) => IO): E.Either; unsafeAddRef(): boolean; get unsafeClosed(): boolean; unsafeDeny(key: Key): boolean; unsafeClose(a: A): IO | null; unsafeRelease(): IO | 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: GlobalScope; /** * A tuple that contains an open scope, together with a function that closes * the scope. */ export declare class Open { readonly close: (_: A) => IO; readonly scope: LocalScope; constructor(close: (_: A) => IO, scope: LocalScope); } export declare const unsafeMakeScope: () => Open; export declare const makeScope: () => IO>; //# sourceMappingURL=Scope.d.ts.map