@emigrate/cli
Advanced tools
Comparing version
@@ -19,2 +19,3 @@ import { setTimeout } from 'node:timers'; | ||
const result = await Promise.race(aborter ? [aborter, fn()] : [fn()]); | ||
aborter?.cancel(); | ||
return [result, undefined]; | ||
@@ -32,13 +33,29 @@ } | ||
*/ | ||
const getAborter = async (signal, respite = DEFAULT_RESPITE_SECONDS * 1000) => { | ||
return new Promise((_, reject) => { | ||
const getAborter = (signal, respite = DEFAULT_RESPITE_SECONDS * 1000) => { | ||
const cleanups = []; | ||
const aborter = new Promise((_, reject) => { | ||
const abortListener = () => { | ||
const timer = setTimeout(reject, respite, ExecutionDesertedError.fromReason(`Deserted after ${prettyMs(respite)}`, toError(signal.reason))); | ||
timer.unref(); | ||
cleanups.push(() => { | ||
clearTimeout(timer); | ||
}); | ||
}; | ||
if (signal.aborted) { | ||
setTimeout(reject, respite, ExecutionDesertedError.fromReason(`Deserted after ${prettyMs(respite)}`, toError(signal.reason))).unref(); | ||
abortListener(); | ||
return; | ||
} | ||
signal.addEventListener('abort', () => { | ||
setTimeout(reject, respite, ExecutionDesertedError.fromReason(`Deserted after ${prettyMs(respite)}`, toError(signal.reason))).unref(); | ||
}, { once: true }); | ||
signal.addEventListener('abort', abortListener, { once: true }); | ||
cleanups.push(() => { | ||
signal.removeEventListener('abort', abortListener); | ||
}); | ||
}); | ||
const cancel = () => { | ||
for (const cleanup of cleanups) { | ||
cleanup(); | ||
} | ||
cleanups.length = 0; | ||
}; | ||
return Object.assign(aborter, { cancel }); | ||
}; | ||
//# sourceMappingURL=exec.js.map |
{ | ||
"name": "@emigrate/cli", | ||
"version": "0.18.0", | ||
"version": "0.18.1", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
329771
0.25%3439
0.5%