export class InterruptLifecycle {
    activeBusyTask;
    createAbortBusyTask() {
        const abortController = new AbortController();
        return {
            signal: abortController.signal,
            busyTask: {
                requestInterrupt: () => {
                    if (abortController.signal.aborted) {
                        return false;
                    }
                    abortController.abort();
                    return true;
                },
            },
        };
    }
    beginBusyTask(task) {
        this.activeBusyTask = task;
    }
    endBusyTask(task) {
        if (this.activeBusyTask === task) {
            this.activeBusyTask = undefined;
        }
    }
    interruptActiveTask() {
        if (!this.activeBusyTask)
            return false;
        return this.activeBusyTask.requestInterrupt();
    }
}
//# sourceMappingURL=interrupt_lifecycle.js.map