@@ -7,20 +7,21 @@ const errors = require('internal/errors');
7
7
* Environment::AsyncHooks::fields_[]. Each index tracks the number of active
8
8
* hooks for each type.
9
9
*
10
- * async_uid_fields is a Float64Array wrapping the double array of
10
+ * async_id_fields is a Float64Array wrapping the double array of
11
11
* Environment::AsyncHooks::uid_fields_[]. Each index contains the ids for the
12
12
* various asynchronous states of the application. These are:
13
- * kCurrentAsyncId : The async_id assigned to the resource responsible for the
13
+ * kExecutionAsyncId : The async_id assigned to the resource responsible for the
14
14
* current execution stack.
15
- * kCurrentTriggerId: The trigger_async_id of the resource responsible for the
16
- * current execution stack.
17
- * kAsyncUidCntr: Incremental counter tracking the next assigned async_id.
18
- * kInitTriggerId: Written immediately before a resource's constructor that
19
- * sets the value of the init()'s triggerAsyncId. The order of retrieving
20
- * the triggerAsyncId value is passing directly to the constructor -> value
21
- * set in kInitTriggerId -> executionAsyncId of the current resource.
15
+ * kTriggerAsyncId: The trigger_async_id of the resource responsible for
16
+ * the current execution stack.
17
+ * kAsyncIdCounter: Incremental counter tracking the next assigned async_id.
18
+ * kInitTriggerAsyncId: Written immediately before a resource's constructor
19
+ * that sets the value of the init()'s triggerAsyncId. The order of
20
+ * retrieving the triggerAsyncId value is passing directly to the
21
+ * constructor -> value set in kInitTriggerAsyncId -> executionAsyncId of
22
+ * the current resource.
22
23
*/
23
- const { async_hook_fields, async_uid_fields } = async_wrap ;
24
+ const { async_hook_fields, async_id_fields } = async_wrap ;
24
25
// Store the pair executionAsyncId and triggerAsyncId in a std::stack on
25
26
// Environment::AsyncHooks::ids_stack_ tracks the resource responsible for the
26
27
// current execution stack. This is unwound as each resource exits. In the case
@@ -59,14 +60,14 @@ const active_hooks = {
59
60
// Each constant tracks how many callbacks there are for any given step of
60
61
// async execution. These are tracked so if the user didn't include callbacks
61
62
// for a given step, that step can bail out early.
62
- const { kInit, kBefore, kAfter, kDestroy, kPromiseResolve , kTotals ,
63
- kCurrentAsyncId , kCurrentTriggerId , kAsyncUidCntr ,
64
- kInitTriggerId } = async_wrap . constants ;
63
+ const { kInit, kBefore, kAfter, kDestroy, kTotals , kPromiseResolve ,
64
+ kExecutionAsyncId , kTriggerAsyncId , kAsyncIdCounter ,
65
+ kInitTriggerAsyncId } = async_wrap . constants ;
65
66
66
67
// Symbols used to store the respective ids on both AsyncResource instances and
67
68
// internal resources. They will also be assigned to arbitrary objects passed
68
69
// in by the user that take place of internally constructed objects.
69
- const { async_id_symbol, trigger_id_symbol } = async_wrap ;
70
+ const { async_id_symbol, trigger_async_id_symbol } = async_wrap ;
70
71
71
72
// Used in AsyncHook and AsyncResource.
72
73
const init_symbol = Symbol ( 'init' ) ;
@@ -235,12 +236,12 @@ function createHook(fns) {
235
236
236
237
237
238
function executionAsyncId ( ) {
238
- return async_uid_fields [ kCurrentAsyncId ] ;
239
+ return async_id_fields [ kExecutionAsyncId ] ;
239
240
}
240
241
241
242
242
243
function triggerAsyncId ( ) {
243
- return async_uid_fields [ kCurrentTriggerId ] ;
244
+ return async_id_fields [ kTriggerAsyncId ] ;
244
245
}
245
246
246
247
@@ -259,14 +260,16 @@ class AsyncResource {
259
260
triggerAsyncId ) ;
260
261
}
261
262
262
- this [ async_id_symbol ] = ++ async_uid_fields [ kAsyncUidCntr ] ;
263
- this [ trigger_id_symbol ] = triggerAsyncId ;
263
+ this [ async_id_symbol ] = ++ async_id_fields [ kAsyncIdCounter ] ;
264
+ this [ trigger_async_id_symbol ] = triggerAsyncId ;
264
265
265
- emitInitScript ( this [ async_id_symbol ] , type , this [ trigger_id_symbol ] , this ) ;
266
+ emitInitScript (
267
+ this [ async_id_symbol ] , type , this [ trigger_async_id_symbol ] , this
268
+ ) ;
266
269
}
267
270
268
271
emitBefore ( ) {
269
- emitBeforeScript ( this [ async_id_symbol ] , this [ trigger_id_symbol ] ) ;
272
+ emitBeforeScript ( this [ async_id_symbol ] , this [ trigger_async_id_symbol ] ) ;
270
273
return this ;
271
274
}
272
275
@@ -285,7 +288,7 @@ class AsyncResource {
285
288
}
286
289
287
290
triggerAsyncId ( ) {
288
- return this [ trigger_id_symbol ] ;
291
+ return this [ trigger_async_id_symbol ] ;
289
292
}
290
293
}
291
294
@@ -320,28 +323,28 @@ function runInAsyncIdScope(asyncId, cb) {
320
323
// counter increment first. Since it's done the same way in
321
324
// Environment::new_async_uid()
322
325
function newUid ( ) {
323
- return ++ async_uid_fields [ kAsyncUidCntr ] ;
326
+ return ++ async_id_fields [ kAsyncIdCounter ] ;
324
327
}
325
328
326
329
327
330
// Return the triggerAsyncId meant for the constructor calling it. It's up to
328
331
// the user to safeguard this call and make sure it's zero'd out when the
329
332
// constructor is complete.
330
333
function initTriggerId ( ) {
331
- var tId = async_uid_fields [ kInitTriggerId ] ;
334
+ var triggerAsyncId = async_id_fields [ kInitTriggerAsyncId ] ;
332
335
// Reset value after it's been called so the next constructor doesn't
333
336
// inherit it by accident.
334
- async_uid_fields [ kInitTriggerId ] = 0 ;
335
- if ( tId <= 0 )
336
- tId = async_uid_fields [ kCurrentAsyncId ] ;
337
- return tId ;
337
+ async_id_fields [ kInitTriggerAsyncId ] = 0 ;
338
+ if ( triggerAsyncId <= 0 )
339
+ triggerAsyncId = async_id_fields [ kExecutionAsyncId ] ;
340
+ return triggerAsyncId ;
338
341
}
339
342
340
343
341
344
function setInitTriggerId ( triggerAsyncId ) {
342
345
// CHECK(Number.isSafeInteger(triggerAsyncId))
343
346
// CHECK(triggerAsyncId > 0)
344
- async_uid_fields [ kInitTriggerId ] = triggerAsyncId ;
347
+ async_id_fields [ kInitTriggerAsyncId ] = triggerAsyncId ;
345
348
}
346
349
347
350
@@ -358,8 +361,9 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) {
358
361
if ( triggerAsyncId === null ) {
359
362
triggerAsyncId = initTriggerId ( ) ;
360
363
} else {
361
- // If a triggerAsyncId was passed, any kInitTriggerId still must be null'd.
362
- async_uid_fields [ kInitTriggerId ] = 0 ;
364
+ // If a triggerAsyncId was passed, any kInitTriggerAsyncId still must be
365
+ // null'd.
366
+ async_id_fields [ kInitTriggerAsyncId ] = 0 ;
363
367
}
364
368
365
369
if ( ! Number . isSafeInteger ( asyncId ) || asyncId < - 1 ) {
@@ -458,7 +462,7 @@ function emitDestroyScript(asyncId) {
458
462
// Return early if there are no destroy callbacks, or invalid asyncId.
459
463
if ( async_hook_fields [ kDestroy ] === 0 || asyncId <= 0 )
460
464
return ;
461
- async_wrap . addIdToDestroyList ( asyncId ) ;
465
+ async_wrap . queueDestroyAsyncId ( asyncId ) ;
462
466
}
463
467
464
468
0 commit comments