@mongodb-js/compass-utils
Advanced tools
Comparing version 0.0.0-next-aaccfd472a61651f2cd223e08a772916adea0d39 to 0.0.0-next-aafcfc5ac487a7962baee26ca6c5870e66de2533
@@ -21,22 +21,2 @@ "use strict"; | ||
exports.isCancelError = isCancelError; | ||
function abortablePromise(abortSignal, successSignal) { | ||
var _a; | ||
if (abortSignal.aborted) { | ||
return Promise.reject((_a = abortSignal.reason) !== null && _a !== void 0 ? _a : (0, exports.createCancelError)()); | ||
} | ||
let reject; | ||
const promise = new Promise(function (_resolve, _reject) { | ||
reject = _reject; | ||
}); | ||
const abort = () => { | ||
successSignal.removeEventListener('abort', succeed); | ||
reject((0, exports.createCancelError)()); | ||
}; | ||
const succeed = () => { | ||
abortSignal.removeEventListener('abort', abort); | ||
}; | ||
abortSignal.addEventListener('abort', abort, { once: true }); | ||
successSignal.addEventListener('abort', succeed, { once: true }); | ||
return promise; | ||
} | ||
async function raceWithAbort(promise, signal) { | ||
@@ -47,11 +27,12 @@ var _a; | ||
} | ||
const successController = new AbortController(); | ||
const abortPromise = abortablePromise(signal, successController.signal); | ||
let abortListener; | ||
const pendingPromise = new Promise((_resolve, reject) => { | ||
abortListener = () => { var _a; return reject((_a = signal.reason) !== null && _a !== void 0 ? _a : (0, exports.createCancelError)()); }; | ||
signal.addEventListener('abort', abortListener, { once: true }); | ||
}); | ||
try { | ||
return await Promise.race([abortPromise, promise]); | ||
return await Promise.race([pendingPromise, promise]); | ||
} | ||
finally { | ||
if (!signal.aborted) { | ||
successController.abort(); | ||
} | ||
abortListener && signal.removeEventListener('abort', abortListener); | ||
} | ||
@@ -58,0 +39,0 @@ } |
@@ -17,3 +17,3 @@ { | ||
"homepage": "https://github.com/mongodb-js/compass", | ||
"version": "0.0.0-next-aaccfd472a61651f2cd223e08a772916adea0d39", | ||
"version": "0.0.0-next-aafcfc5ac487a7962baee26ca6c5870e66de2533", | ||
"repository": { | ||
@@ -58,6 +58,6 @@ "type": "git", | ||
"devDependencies": { | ||
"@mongodb-js/eslint-config-compass": "0.0.0-next-aaccfd472a61651f2cd223e08a772916adea0d39", | ||
"@mongodb-js/mocha-config-compass": "0.0.0-next-aaccfd472a61651f2cd223e08a772916adea0d39", | ||
"@mongodb-js/prettier-config-compass": "0.0.0-next-aaccfd472a61651f2cd223e08a772916adea0d39", | ||
"@mongodb-js/tsconfig-compass": "0.0.0-next-aaccfd472a61651f2cd223e08a772916adea0d39", | ||
"@mongodb-js/eslint-config-compass": "0.0.0-next-aafcfc5ac487a7962baee26ca6c5870e66de2533", | ||
"@mongodb-js/mocha-config-compass": "0.0.0-next-aafcfc5ac487a7962baee26ca6c5870e66de2533", | ||
"@mongodb-js/prettier-config-compass": "0.0.0-next-aafcfc5ac487a7962baee26ca6c5870e66de2533", | ||
"@mongodb-js/tsconfig-compass": "0.0.0-next-aafcfc5ac487a7962baee26ca6c5870e66de2533", | ||
"@types/chai": "^4.2.21", | ||
@@ -76,3 +76,3 @@ "@types/mocha": "^9.0.0", | ||
}, | ||
"gitHead": "aaccfd472a61651f2cd223e08a772916adea0d39" | ||
"gitHead": "aafcfc5ac487a7962baee26ca6c5870e66de2533" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1468
15
21
44234
126
25
6
183