"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbortContext = void 0;
class AbortContext {
    constructor() {
        this.stopped = false;
        this.resolve = () => {
            throw new Error('resolve() not available yet');
        };
        this.promise = new Promise((resolve) => {
            this.resolve = resolve;
        });
    }
    get running() {
        return !this.stopped;
    }
    abort() {
        this.stopped = true;
        this.resolve();
    }
    async wait(promise) {
        if (promise) {
            await Promise.race([this.promise, promise]);
        }
        else {
            await this.promise;
        }
    }
}
exports.AbortContext = AbortContext;
//# sourceMappingURL=abort-context.js.map