summaryrefslogtreecommitdiff
path: root/lib/timers.js
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2018-05-23 02:01:53 +0400
committerAnatoli Papirovski <apapirovski@mac.com>2018-06-01 10:29:51 +0200
commit48a2568f411cf09999b7e82992d15142ce9a45b0 (patch)
tree3758361e4577bd5a253f17a25ef726f30a9b96e0 /lib/timers.js
parentde732725d8ae232d7b6d56927ea8bef471d5bf1d (diff)
downloadandroid-node-v8-48a2568f411cf09999b7e82992d15142ce9a45b0.tar.gz
android-node-v8-48a2568f411cf09999b7e82992d15142ce9a45b0.tar.bz2
android-node-v8-48a2568f411cf09999b7e82992d15142ce9a45b0.zip
timers: add hasRef method to Timeout & Immediate
Provide a way to check whether the current timer or immediate is refed. PR-URL: https://github.com/nodejs/node/pull/20898 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'lib/timers.js')
-rw-r--r--lib/timers.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/timers.js b/lib/timers.js
index 3d200344a4..5ae0e6a5ad 100644
--- a/lib/timers.js
+++ b/lib/timers.js
@@ -547,6 +547,10 @@ Timeout.prototype.ref = function() {
return this;
};
+Timeout.prototype.hasRef = function() {
+ return !!this[kRefed];
+};
+
Timeout.prototype.close = function() {
clearTimeout(this);
return this;
@@ -622,7 +626,7 @@ function processImmediate() {
count++;
if (immediate[kRefed])
refCount++;
- immediate[kRefed] = undefined;
+ immediate[kRefed] = null;
tryOnImmediate(immediate, tail, count, refCount);
@@ -713,6 +717,10 @@ const Immediate = class Immediate {
}
return this;
}
+
+ hasRef() {
+ return !!this[kRefed];
+ }
};
function setImmediate(callback, arg1, arg2, arg3) {
@@ -761,7 +769,7 @@ exports.clearImmediate = function clearImmediate(immediate) {
if (immediate[kRefed] && --immediateInfo[kRefCount] === 0)
toggleImmediateRef(false);
- immediate[kRefed] = undefined;
+ immediate[kRefed] = null;
if (destroyHooksExist()) {
emitDestroy(immediate[async_id_symbol]);