import { AbortError } from '@libp2p/interface';
import pDefer from 'p-defer';
export class JobRecipient {
    deferred;
    signal;
    onProgress;
    constructor(options) {
        this.signal = options?.signal;
        this.onProgress = options?.onProgress;
        this.deferred = pDefer();
        this.onAbort = this.onAbort.bind(this);
        this.signal?.addEventListener('abort', this.onAbort);
    }
    onAbort() {
        this.deferred.reject(this.signal?.reason ?? new AbortError());
    }
    cleanup() {
        this.signal?.removeEventListener('abort', this.onAbort);
    }
}
//# sourceMappingURL=recipient.js.map