"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.abortableSleep = abortableSleep;
/**
 * Promise-based sleep that resolves early when the supplied AbortSignal
 * fires. Returns true if the wait completed normally; false if the
 * abort triggered. Used by the reviewer/doer retry loops so a cancelled
 * chat doesn't wait the full backoff before tearing down.
 */
function abortableSleep(ms, signal) {
    if (signal.aborted)
        return Promise.resolve(false);
    return new Promise((resolve) => {
        const timer = setTimeout(() => {
            signal.removeEventListener('abort', onAbort);
            resolve(true);
        }, ms);
        const onAbort = () => {
            clearTimeout(timer);
            signal.removeEventListener('abort', onAbort);
            resolve(false);
        };
        signal.addEventListener('abort', onAbort, { once: true });
    });
}
//# sourceMappingURL=abortable-sleep.js.map