"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbortError = void 0; // note: this is not a real error for performance reasons // if abort errors occur frequently, creating error stacks // can slow down your application. // if you want AbortErrors to have stacks use ./raceAbortError class AbortError { constructor() { this.name = 'AbortError'; this.message = 'aborted'; this.stack = 'AbortError: aborted'; } } exports.AbortError = AbortError; Object.setPrototypeOf(AbortError.prototype, Error.prototype); async function raceAbort(opts, taskOrPromise) { let signal; let _AbortError; if (opts.signal) { signal = opts.signal; _AbortError = opts.AbortError; } else { signal = opts; _AbortError = AbortError; // default to non-error AbortError class, for performance } let handleAbort; try { return await new Promise((resolve, reject) => { handleAbort = () => reject(new _AbortError()); if (signal.aborted) { // @ts-ignore - ignore promise errors if (taskOrPromise?.catch) taskOrPromise.catch((err) => { }); return void handleAbort(); } signal.addEventListener('abort', handleAbort); const promise = Promise.resolve(typeof taskOrPromise === 'function' ? taskOrPromise(signal) : taskOrPromise); promise.then(resolve, reject); }); } finally { // @ts-ignore signal.removeEventListener('abort', handleAbort); } } exports.default = raceAbort; //# sourceMappingURL=index.js.map