async_hooks: rename AsyncEvent to AsyncResource

`AsyncEvent` is not a good name given its semantics.

PR-URL: https://github.com/nodejs/node/pull/13192
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Anna Henningsen 2017-05-24 13:15:05 +02:00
parent b153420fd9
commit 90dee89d8e
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF
6 changed files with 18 additions and 18 deletions

View File

@ -43,7 +43,7 @@ const { kInit, kBefore, kAfter, kDestroy, kCurrentAsyncId, kCurrentTriggerId,
const { async_id_symbol, trigger_id_symbol } = async_wrap; const { async_id_symbol, trigger_id_symbol } = async_wrap;
// Used in AsyncHook and AsyncEvent. // Used in AsyncHook and AsyncResource.
const init_symbol = Symbol('init'); const init_symbol = Symbol('init');
const before_symbol = Symbol('before'); const before_symbol = Symbol('before');
const after_symbol = Symbol('after'); const after_symbol = Symbol('after');
@ -192,7 +192,7 @@ function triggerId() {
// Embedder API // // Embedder API //
class AsyncEvent { class AsyncResource {
constructor(type, triggerId) { constructor(type, triggerId) {
this[async_id_symbol] = ++async_uid_fields[kAsyncUidCntr]; this[async_id_symbol] = ++async_uid_fields[kAsyncUidCntr];
// Read and reset the current kInitTriggerId so that when the constructor // Read and reset the current kInitTriggerId so that when the constructor
@ -480,7 +480,7 @@ module.exports = {
currentId, currentId,
triggerId, triggerId,
// Embedder API // Embedder API
AsyncEvent, AsyncResource,
runInAsyncIdScope, runInAsyncIdScope,
// Sensitive Embedder API // Sensitive Embedder API
newUid, newUid,

View File

@ -3,7 +3,7 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const async_hooks = require('async_hooks'); const async_hooks = require('async_hooks');
const { AsyncEvent } = async_hooks; const { AsyncResource } = async_hooks;
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const corruptedMsg = /async hook stack has become corrupted/; const corruptedMsg = /async hook stack has become corrupted/;
const heartbeatMsg = /heartbeat: still alive/; const heartbeatMsg = /heartbeat: still alive/;
@ -17,13 +17,13 @@ if (process.argv[2] === 'child') {
// once 'destroy' has been emitted, we can no longer emit 'after' // once 'destroy' has been emitted, we can no longer emit 'after'
// Emitting 'before', 'after' and then 'destroy' // Emitting 'before', 'after' and then 'destroy'
const event1 = new AsyncEvent('event1', async_hooks.currentId()); const event1 = new AsyncResource('event1', async_hooks.currentId());
event1.emitBefore(); event1.emitBefore();
event1.emitAfter(); event1.emitAfter();
event1.emitDestroy(); event1.emitDestroy();
// Emitting 'after' after 'destroy' // Emitting 'after' after 'destroy'
const event2 = new AsyncEvent('event2', async_hooks.currentId()); const event2 = new AsyncResource('event2', async_hooks.currentId());
event2.emitDestroy(); event2.emitDestroy();
console.log('heartbeat: still alive'); console.log('heartbeat: still alive');

View File

@ -3,7 +3,7 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const async_hooks = require('async_hooks'); const async_hooks = require('async_hooks');
const { AsyncEvent } = async_hooks; const { AsyncResource } = async_hooks;
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const corruptedMsg = /async hook stack has become corrupted/; const corruptedMsg = /async hook stack has become corrupted/;
const heartbeatMsg = /heartbeat: still alive/; const heartbeatMsg = /heartbeat: still alive/;
@ -17,13 +17,13 @@ if (process.argv[2] === 'child') {
// once 'destroy' has been emitted, we can no longer emit 'before' // once 'destroy' has been emitted, we can no longer emit 'before'
// Emitting 'before', 'after' and then 'destroy' // Emitting 'before', 'after' and then 'destroy'
const event1 = new AsyncEvent('event1', async_hooks.currentId()); const event1 = new AsyncResource('event1', async_hooks.currentId());
event1.emitBefore(); event1.emitBefore();
event1.emitAfter(); event1.emitAfter();
event1.emitDestroy(); event1.emitDestroy();
// Emitting 'before' after 'destroy' // Emitting 'before' after 'destroy'
const event2 = new AsyncEvent('event2', async_hooks.currentId()); const event2 = new AsyncResource('event2', async_hooks.currentId());
event2.emitDestroy(); event2.emitDestroy();
console.log('heartbeat: still alive'); console.log('heartbeat: still alive');

View File

@ -3,7 +3,7 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const async_hooks = require('async_hooks'); const async_hooks = require('async_hooks');
const { AsyncEvent } = async_hooks; const { AsyncResource } = async_hooks;
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const corruptedMsg = /async hook stack has become corrupted/; const corruptedMsg = /async hook stack has become corrupted/;
const heartbeatMsg = /heartbeat: still alive/; const heartbeatMsg = /heartbeat: still alive/;
@ -17,13 +17,13 @@ if (process.argv[2] === 'child') {
// async hooks enforce proper order of 'before' and 'after' invocations // async hooks enforce proper order of 'before' and 'after' invocations
// Proper ordering // Proper ordering
const event1 = new AsyncEvent('event1', async_hooks.currentId()); const event1 = new AsyncResource('event1', async_hooks.currentId());
event1.emitBefore(); event1.emitBefore();
event1.emitAfter(); event1.emitAfter();
// Improper ordering // Improper ordering
// Emitting 'after' without 'before' which is illegal // Emitting 'after' without 'before' which is illegal
const event2 = new AsyncEvent('event2', async_hooks.currentId()); const event2 = new AsyncResource('event2', async_hooks.currentId());
console.log('heartbeat: still alive'); console.log('heartbeat: still alive');
event2.emitAfter(); event2.emitAfter();

View File

@ -3,7 +3,7 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const async_hooks = require('async_hooks'); const async_hooks = require('async_hooks');
const { AsyncEvent } = async_hooks; const { AsyncResource } = async_hooks;
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const corruptedMsg = /async hook stack has become corrupted/; const corruptedMsg = /async hook stack has become corrupted/;
const heartbeatMsg = /heartbeat: still alive/; const heartbeatMsg = /heartbeat: still alive/;
@ -21,8 +21,8 @@ if (process.argv[2] === 'child') {
// The first test of the two below follows that rule, // The first test of the two below follows that rule,
// the second one doesnt. // the second one doesnt.
const event1 = new AsyncEvent('event1', async_hooks.currentId()); const event1 = new AsyncResource('event1', async_hooks.currentId());
const event2 = new AsyncEvent('event2', async_hooks.currentId()); const event2 = new AsyncResource('event2', async_hooks.currentId());
// Proper unwind // Proper unwind
event1.emitBefore(); event1.emitBefore();

View File

@ -4,7 +4,7 @@ const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const tick = require('./tick'); const tick = require('./tick');
const async_hooks = require('async_hooks'); const async_hooks = require('async_hooks');
const { AsyncEvent } = async_hooks; const { AsyncResource } = async_hooks;
const initHooks = require('./init-hooks'); const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks'); const { checkInvocations } = require('./hook-checks');
@ -15,7 +15,7 @@ hooks.enable();
// create first custom event 'alcazares' with triggerId derived // create first custom event 'alcazares' with triggerId derived
// from async_hooks currentId // from async_hooks currentId
const alcaTriggerId = async_hooks.currentId(); const alcaTriggerId = async_hooks.currentId();
const alcaEvent = new AsyncEvent('alcazares', alcaTriggerId); const alcaEvent = new AsyncResource('alcazares', alcaTriggerId);
const alcazaresActivities = hooks.activitiesOfTypes([ 'alcazares' ]); const alcazaresActivities = hooks.activitiesOfTypes([ 'alcazares' ]);
// alcazares event was constructed and thus only has an `init` call // alcazares event was constructed and thus only has an `init` call
@ -49,7 +49,7 @@ function tick1() {
// The below shows that we can pass any number as a trigger id // The below shows that we can pass any number as a trigger id
const pobTriggerId = 111; const pobTriggerId = 111;
const pobEvent = new AsyncEvent('poblado', pobTriggerId); const pobEvent = new AsyncResource('poblado', pobTriggerId);
const pobladoActivities = hooks.activitiesOfTypes([ 'poblado' ]); const pobladoActivities = hooks.activitiesOfTypes([ 'poblado' ]);
const poblado = pobladoActivities[0]; const poblado = pobladoActivities[0];
assert.strictEqual(poblado.type, 'poblado', 'poblado'); assert.strictEqual(poblado.type, 'poblado', 'poblado');