@@ -58,8 +58,8 @@ const active_hooks = {
5858// Each constant tracks how many callbacks there are for any given step of
5959// async execution. These are tracked so if the user didn't include callbacks
6060// for a given step, that step can bail out early.
61- const { kInit, kBefore, kAfter, kDestroy, kTotals , kCurrentAsyncId ,
62- kCurrentTriggerId, kAsyncUidCntr,
61+ const { kInit, kBefore, kAfter, kDestroy, kPromiseResolve , kTotals ,
62+ kCurrentAsyncId , kCurrentTriggerId, kAsyncUidCntr,
6363 kInitTriggerId } = async_wrap . constants ;
6464
6565// Symbols used to store the respective ids on both AsyncResource instances and
@@ -72,9 +72,12 @@ const init_symbol = Symbol('init');
7272const before_symbol = Symbol ( 'before' ) ;
7373const after_symbol = Symbol ( 'after' ) ;
7474const destroy_symbol = Symbol ( 'destroy' ) ;
75+ const promise_resolve_symbol = Symbol ( 'promiseResolve' ) ;
7576const emitBeforeNative = emitHookFactory ( before_symbol , 'emitBeforeNative' ) ;
7677const emitAfterNative = emitHookFactory ( after_symbol , 'emitAfterNative' ) ;
7778const emitDestroyNative = emitHookFactory ( destroy_symbol , 'emitDestroyNative' ) ;
79+ const emitPromiseResolveNative =
80+ emitHookFactory ( promise_resolve_symbol , 'emitPromiseResolveNative' ) ;
7881
7982// TODO(refack): move to node-config.cc
8083const abort_regex = / ^ - - a b o r t [ _ - ] o n [ _ - ] u n c a u g h t [ _ - ] e x c e p t i o n $ / ;
@@ -86,7 +89,8 @@ const abort_regex = /^--abort[_-]on[_-]uncaught[_-]exception$/;
8689async_wrap . setupHooks ( { init : emitInitNative ,
8790 before : emitBeforeNative ,
8891 after : emitAfterNative ,
89- destroy : emitDestroyNative } ) ;
92+ destroy : emitDestroyNative ,
93+ promise_resolve : emitPromiseResolveNative } ) ;
9094
9195// Used to fatally abort the process if a callback throws.
9296function fatalError ( e ) {
@@ -107,7 +111,7 @@ function fatalError(e) {
107111// Public API //
108112
109113class AsyncHook {
110- constructor ( { init, before, after, destroy } ) {
114+ constructor ( { init, before, after, destroy, promiseResolve } ) {
111115 if ( init !== undefined && typeof init !== 'function' )
112116 throw new errors . TypeError ( 'ERR_ASYNC_CALLBACK' , 'init' ) ;
113117 if ( before !== undefined && typeof before !== 'function' )
@@ -116,11 +120,14 @@ class AsyncHook {
116120 throw new errors . TypeError ( 'ERR_ASYNC_CALLBACK' , 'before' ) ;
117121 if ( destroy !== undefined && typeof destroy !== 'function' )
118122 throw new errors . TypeError ( 'ERR_ASYNC_CALLBACK' , 'before' ) ;
123+ if ( promiseResolve !== undefined && typeof promiseResolve !== 'function' )
124+ throw new errors . TypeError ( 'ERR_ASYNC_CALLBACK' , 'promiseResolve' ) ;
119125
120126 this [ init_symbol ] = init ;
121127 this [ before_symbol ] = before ;
122128 this [ after_symbol ] = after ;
123129 this [ destroy_symbol ] = destroy ;
130+ this [ promise_resolve_symbol ] = promiseResolve ;
124131 }
125132
126133 enable ( ) {
@@ -144,6 +151,8 @@ class AsyncHook {
144151 hook_fields [ kTotals ] += hook_fields [ kBefore ] += + ! ! this [ before_symbol ] ;
145152 hook_fields [ kTotals ] += hook_fields [ kAfter ] += + ! ! this [ after_symbol ] ;
146153 hook_fields [ kTotals ] += hook_fields [ kDestroy ] += + ! ! this [ destroy_symbol ] ;
154+ hook_fields [ kTotals ] +=
155+ hook_fields [ kPromiseResolve ] += + ! ! this [ promise_resolve_symbol ] ;
147156 hooks_array . push ( this ) ;
148157
149158 if ( prev_kTotals === 0 && hook_fields [ kTotals ] > 0 )
@@ -166,6 +175,8 @@ class AsyncHook {
166175 hook_fields [ kTotals ] += hook_fields [ kBefore ] -= + ! ! this [ before_symbol ] ;
167176 hook_fields [ kTotals ] += hook_fields [ kAfter ] -= + ! ! this [ after_symbol ] ;
168177 hook_fields [ kTotals ] += hook_fields [ kDestroy ] -= + ! ! this [ destroy_symbol ] ;
178+ hook_fields [ kTotals ] +=
179+ hook_fields [ kPromiseResolve ] -= + ! ! this [ promise_resolve_symbol ] ;
169180 hooks_array . splice ( index , 1 ) ;
170181
171182 if ( prev_kTotals > 0 && hook_fields [ kTotals ] === 0 )
@@ -198,6 +209,7 @@ function storeActiveHooks() {
198209 active_hooks . tmp_fields [ kBefore ] = async_hook_fields [ kBefore ] ;
199210 active_hooks . tmp_fields [ kAfter ] = async_hook_fields [ kAfter ] ;
200211 active_hooks . tmp_fields [ kDestroy ] = async_hook_fields [ kDestroy ] ;
212+ active_hooks . tmp_fields [ kPromiseResolve ] = async_hook_fields [ kPromiseResolve ] ;
201213}
202214
203215
@@ -209,6 +221,7 @@ function restoreActiveHooks() {
209221 async_hook_fields [ kBefore ] = active_hooks . tmp_fields [ kBefore ] ;
210222 async_hook_fields [ kAfter ] = active_hooks . tmp_fields [ kAfter ] ;
211223 async_hook_fields [ kDestroy ] = active_hooks . tmp_fields [ kDestroy ] ;
224+ async_hook_fields [ kPromiseResolve ] = active_hooks . tmp_fields [ kPromiseResolve ] ;
212225
213226 active_hooks . tmp_array = null ;
214227 active_hooks . tmp_fields = null ;
0 commit comments