2222'use strict' ;
2323
2424const async_wrap = process . binding ( 'async_wrap' ) ;
25- const TimerWrap = process . binding ( 'timer_wrap' ) . Timer ;
25+ const {
26+ Timer : TimerWrap ,
27+ setImmediateCallback,
28+ } = process . binding ( 'timer_wrap' ) ;
2629const L = require ( 'internal/linkedlist' ) ;
2730const timerInternals = require ( 'internal/timers' ) ;
2831const internalUtil = require ( 'internal/util' ) ;
@@ -48,12 +51,8 @@ const { kInit, kDestroy, kAsyncIdCounter } = async_wrap.constants;
4851const async_id_symbol = timerInternals . async_id_symbol ;
4952const trigger_async_id_symbol = timerInternals . trigger_async_id_symbol ;
5053
51- /* This is an Uint32Array for easier sharing with C++ land. */
52- const scheduledImmediateCount = process . _scheduledImmediateCount ;
53- delete process . _scheduledImmediateCount ;
54- /* Kick off setImmediate processing */
55- const activateImmediateCheck = process . _activateImmediateCheck ;
56- delete process . _activateImmediateCheck ;
54+ const [ activateImmediateCheck , scheduledImmediateCountArray ] =
55+ setImmediateCallback ( processImmediate ) ;
5756
5857// The Timeout class
5958const Timeout = timerInternals . Timeout ;
@@ -676,8 +675,6 @@ function processImmediate() {
676675 }
677676}
678677
679- process . _immediateCallback = processImmediate ;
680-
681678// An optimization so that the try/finally only de-optimizes (since at least v8
682679// 4.7) what is in this smaller function.
683680function tryOnImmediate ( immediate , oldTail ) {
@@ -694,7 +691,7 @@ function tryOnImmediate(immediate, oldTail) {
694691
695692 if ( ! immediate . _destroyed ) {
696693 immediate . _destroyed = true ;
697- scheduledImmediateCount [ 0 ] -- ;
694+ scheduledImmediateCountArray [ 0 ] -- ;
698695
699696 if ( async_hook_fields [ kDestroy ] > 0 ) {
700697 emitDestroy ( immediate [ async_id_symbol ] ) ;
@@ -748,9 +745,9 @@ function Immediate(callback, args) {
748745 this ) ;
749746 }
750747
751- if ( scheduledImmediateCount [ 0 ] === 0 )
748+ if ( scheduledImmediateCountArray [ 0 ] === 0 )
752749 activateImmediateCheck ( ) ;
753- scheduledImmediateCount [ 0 ] ++ ;
750+ scheduledImmediateCountArray [ 0 ] ++ ;
754751
755752 immediateQueue . append ( this ) ;
756753}
@@ -796,7 +793,7 @@ exports.clearImmediate = function(immediate) {
796793 if ( ! immediate ) return ;
797794
798795 if ( ! immediate . _destroyed ) {
799- scheduledImmediateCount [ 0 ] -- ;
796+ scheduledImmediateCountArray [ 0 ] -- ;
800797 immediate . _destroyed = true ;
801798
802799 if ( async_hook_fields [ kDestroy ] > 0 ) {
0 commit comments