mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
timers: fix multipleResolves in promisified timeouts/immediates
After successful timer finish the abort event callback would still reject (already resolved promise) upon calling abortController.abort(). Signed-off-by: Denys Otrishko <shishugi@gmail.com> PR-URL: https://github.com/nodejs/node/pull/33949 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
51a2df4439
commit
64d22c320c
2 changed files with 27 additions and 4 deletions
|
@ -190,8 +190,10 @@ setTimeout[customPromisify] = function(after, value, options = {}) {
|
|||
insert(timeout, timeout._idleTimeout);
|
||||
if (signal) {
|
||||
signal.addEventListener('abort', () => {
|
||||
clearTimeout(timeout);
|
||||
reject(lazyDOMException('AbortError'));
|
||||
if (!timeout._destroyed) {
|
||||
clearTimeout(timeout);
|
||||
reject(lazyDOMException('AbortError'));
|
||||
}
|
||||
}, { once: true });
|
||||
}
|
||||
});
|
||||
|
@ -340,8 +342,10 @@ setImmediate[customPromisify] = function(value, options = {}) {
|
|||
const immediate = new Immediate(resolve, [value]);
|
||||
if (signal) {
|
||||
signal.addEventListener('abort', () => {
|
||||
clearImmediate(immediate);
|
||||
reject(lazyDOMException('AbortError'));
|
||||
if (!immediate._destroyed) {
|
||||
clearImmediate(immediate);
|
||||
reject(lazyDOMException('AbortError'));
|
||||
}
|
||||
}, { once: true });
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue