timers: refactor to use more primordials

PR-URL: https://github.com/nodejs/node/pull/36132
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
pull/36132/head
Antoine du Hamel 2020-11-15 18:12:43 +01:00 committed by Rich Trott
parent 8938d37251
commit bd120207fb
1 changed files with 7 additions and 4 deletions

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const { const {
FunctionPrototypeBind,
Promise, Promise,
PromisePrototypeFinally, PromisePrototypeFinally,
PromiseReject, PromiseReject,
@ -72,8 +73,9 @@ function setTimeout(after, value, options = {}) {
if (!ref) timeout.unref(); if (!ref) timeout.unref();
insert(timeout, timeout._idleTimeout); insert(timeout, timeout._idleTimeout);
if (signal) { if (signal) {
// eslint-disable-next-line no-undef oncancel = FunctionPrototypeBind(cancelListenerHandler,
oncancel = cancelListenerHandler.bind(timeout, clearTimeout, reject); // eslint-disable-next-line no-undef
timeout, clearTimeout, reject);
signal.addEventListener('abort', oncancel); signal.addEventListener('abort', oncancel);
} }
}); });
@ -121,8 +123,9 @@ function setImmediate(value, options = {}) {
const immediate = new Immediate(resolve, [value]); const immediate = new Immediate(resolve, [value]);
if (!ref) immediate.unref(); if (!ref) immediate.unref();
if (signal) { if (signal) {
// eslint-disable-next-line no-undef oncancel = FunctionPrototypeBind(cancelListenerHandler,
oncancel = cancelListenerHandler.bind(immediate, clearImmediate, reject); // eslint-disable-next-line no-undef
immediate, clearImmediate, reject);
signal.addEventListener('abort', oncancel); signal.addEventListener('abort', oncancel);
} }
}); });