/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { Duration } from "#time/Duration.js"; import { Callable } from "./Function.js"; /** * Convenience abort implementation. * * Acts as both an {@link AbortController} and {@link AbortSignal}. * * May be awaited like a promise, although it returns the {@link reason} rather than throwing. * * May be invoked as a function to perform abort. * * Optionally will register for abort with an outer {@link AbortController} and/or add a timeout. You must abort or * invoke {@link close} if you use either of these options. */ export declare class Abort extends Callable<[reason?: string | Error]> implements AbortController, AbortSignal, PromiseLike { #private; constructor({ abort: aborts, timeout, handler, timeoutHandler }?: Abort.Options); abort(reason?: Error | string): void; get signal(): AbortSignal; /** * Race one or more promises with my abort signal. * * If aborted returns undefined. */ race(...promises: Array>): Promise | void>; /** * Race with throw on abort. */ attempt(...promises: Array>): Promise; /** * Free resources. * * You must abort or invoke {@link close} when finished if you construct with {@link Abort.Options#abort} or * {@link Abort.Options#timeout}. */ close(): void; [Symbol.dispose](): void; if(condition?: unknown, reason?: Error): void; get aborted(): boolean; set onabort(onabort: ((this: AbortSignal, ev: Event) => any) | null); get onabort(): ((this: AbortSignal, ev: Event) => any) | null; get reason(): any; throwIfAborted(): void; then(onfulfilled?: ((value: Error) => TResult1 | PromiseLike) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | null): Promise; addEventListener(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; dispatchEvent(event: Event): boolean; } /** * Utilities for implementing abort logic. */ export declare namespace Abort { /** * Optional configuration for {@link Abort}. */ interface Options { /** * One or more parent abort signals. * * If a parent aborts, this {@link Abort} will abort as well. However the inverse is not true, so this task is * independently abortable. * * This functions similarly to {@link AbortSignal.any} but has additional protection against memory leaks. */ abort?: Signal | (Signal | undefined)[]; /** * An abort timeout. * * If you specify a timeout, you must either abort or close the {@link Abort}. */ timeout?: Duration; /** * Adds a default abort handler. */ handler?: (this: Abort, reason?: Error) => void; /** * Replaces the default timeout handler. * * The default implementation aborts with {@link TimeoutError}. */ timeoutHandler?: (this: Abort) => void; } /** * An entity that may be used to signal abort of an operation. */ type Signal = AbortController | AbortSignal; /** * Determine whether a {@link Signal} is aborted. */ function is(signal: Signal | undefined): boolean | undefined; /** * Race one or more promises with an optional abort signal. * * If the abort signal is present and signals abort, the race will end and return undefined. It will not throw the * abort reason. */ function race(signal: Signal | undefined, ...promises: Array>): Promise | void>; /** * Race with throw on abort. */ function attempt(signal: Signal | undefined, ...promises: Array>): Promise; /** * Perform abortable sleep. */ function sleep(description: string, abort: Signal | undefined, duration: Duration): Promise; /** * Create independently abortable subtask with a new {@link AbortController} that is aborted if another controller * aborts. * * Closing the returned controller unregisters with the input controller. It does not perform an abort. * * {@link timeout} is a convenience for adding a timeout. */ function subtask(signal: Signal | undefined, timeout?: Duration): Abort; /** * Like {@link AbortSignal.any} but does not leak memory so long as the returned {@link Abort} is aborted or closed. */ function any(...signals: (Signal | undefined)[]): Abort; /** * Generate a function that will throw if aborted. */ function checkerFor(signal?: Signal | { abort?: Signal; }): () => void; } //# sourceMappingURL=Abort.d.ts.map