summaryrefslogtreecommitdiff
path: root/lib/internal/timers.js
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2018-02-11 19:20:42 -0500
committerAnatoli Papirovski <apapirovski@mac.com>2018-02-19 07:02:21 -0500
commit28f3ffba0fd732fb8faa49e02049dfb1ee5c5911 (patch)
tree3a4410808404cae73d743b261821d0a2727f1d98 /lib/internal/timers.js
parent30f89dfbf65840025f5c833457702f13aa38fe77 (diff)
downloadandroid-node-v8-28f3ffba0fd732fb8faa49e02049dfb1ee5c5911.tar.gz
android-node-v8-28f3ffba0fd732fb8faa49e02049dfb1ee5c5911.tar.bz2
android-node-v8-28f3ffba0fd732fb8faa49e02049dfb1ee5c5911.zip
timers: add helper fn for async init
There are currently 3 places in Timers where the exact same code appears. Instead create a helper function that does the same job of setting asyncId & triggerAsyncId, as well as calling emitInit. PR-URL: https://github.com/nodejs/node/pull/18825 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib/internal/timers.js')
-rw-r--r--lib/internal/timers.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/internal/timers.js b/lib/internal/timers.js
index 0c140811f8..8c1a87a65f 100644
--- a/lib/internal/timers.js
+++ b/lib/internal/timers.js
@@ -24,6 +24,7 @@ module.exports = {
async_id_symbol,
trigger_async_id_symbol,
Timeout,
+ initAsyncResource,
refreshFnSymbol,
setUnrefTimeout,
validateTimerDuration
@@ -37,6 +38,14 @@ function getTimers() {
return timers;
}
+function initAsyncResource(resource, type) {
+ const asyncId = resource[async_id_symbol] = newAsyncId();
+ const triggerAsyncId =
+ resource[trigger_async_id_symbol] = getDefaultTriggerAsyncId();
+ if (initHooksExist())
+ emitInit(asyncId, type, triggerAsyncId, resource);
+}
+
// Timer constructor function.
// The entire prototype is defined in lib/timers.js
function Timeout(callback, after, args, isRepeat, isUnrefed) {
@@ -66,14 +75,7 @@ function Timeout(callback, after, args, isRepeat, isUnrefed) {
this[unrefedSymbol] = isUnrefed;
- this[async_id_symbol] = newAsyncId();
- this[trigger_async_id_symbol] = getDefaultTriggerAsyncId();
- if (initHooksExist()) {
- emitInit(this[async_id_symbol],
- 'Timeout',
- this[trigger_async_id_symbol],
- this);
- }
+ initAsyncResource(this, 'Timeout');
}
Timeout.prototype[refreshFnSymbol] = function refresh() {