summaryrefslogtreecommitdiff
path: root/lib/internal/timers.js
diff options
context:
space:
mode:
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() {