Skip to content

Commit 2ea5697

Browse files
mcollinaQard
authored andcommitted
rename to ExecutionAsyncResource
1 parent 33fd752 commit 2ea5697

6 files changed

Lines changed: 29 additions & 28 deletions

File tree

lib/async_hooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const {
2424
getHookArrays,
2525
enableHooks,
2626
disableHooks,
27-
currentResource,
27+
executionAsyncResource,
2828
// Internal Embedder API
2929
newAsyncId,
3030
getDefaultTriggerAsyncId,
@@ -206,7 +206,7 @@ module.exports = {
206206
createHook,
207207
executionAsyncId,
208208
triggerAsyncId,
209-
currentResource,
209+
executionAsyncResource,
210210
// Embedder API
211211
AsyncResource,
212212
};

lib/internal/async_hooks.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const active_hooks = {
7676
const { registerDestroyHook } = async_wrap;
7777
const { enqueueMicrotask } = internalBinding('task_queue');
7878

79-
const { currentResource, setCurrentResource } = async_wrap;
79+
const { executionAsyncResource, setExecutionAsyncResource } = async_wrap;
8080

8181
// Each constant tracks how many callbacks there are for any given step of
8282
// async execution. These are tracked so if the user didn't include callbacks
@@ -360,7 +360,7 @@ function emitBeforeScript(asyncId, triggerAsyncId, resource) {
360360
validateAsyncId(asyncId, 'asyncId');
361361
validateAsyncId(triggerAsyncId, 'triggerAsyncId');
362362

363-
setCurrentResource(resource);
363+
setExecutionAsyncResource(resource);
364364
pushAsyncIds(asyncId, triggerAsyncId);
365365

366366
if (async_hook_fields[kBefore] > 0)
@@ -374,7 +374,7 @@ function emitAfterScript(asyncId) {
374374
if (async_hook_fields[kAfter] > 0)
375375
emitAfterNative(asyncId);
376376

377-
setCurrentResource(null);
377+
setExecutionAsyncResource(null);
378378

379379
popAsyncIds(asyncId);
380380
}
@@ -463,7 +463,7 @@ module.exports = {
463463
clearDefaultTriggerAsyncId,
464464
clearAsyncIdStack,
465465
hasAsyncIdStack,
466-
currentResource,
466+
executionAsyncResource,
467467
// Internal Embedder API
468468
newAsyncId,
469469
getOrSetAsyncId,
@@ -477,7 +477,7 @@ module.exports = {
477477
emitAfter: emitAfterScript,
478478
emitDestroy: emitDestroyScript,
479479
registerDestroyHook,
480-
setCurrentResource,
480+
setExecutionAsyncResource,
481481
nativeHooks: {
482482
init: emitInitNative,
483483
before: emitBeforeNative,

lib/internal/timers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const {
9797
emitBefore,
9898
emitAfter,
9999
emitDestroy,
100-
setCurrentResource
100+
setExecutionAsyncResource
101101
} = require('internal/async_hooks');
102102

103103
// Symbols for storing async id state.
@@ -539,7 +539,7 @@ function getTimerCallbacks(runNextTicks) {
539539
else
540540
timer._onTimeout(...args);
541541
} finally {
542-
setCurrentResource(null);
542+
setExecutionAsyncResource(null);
543543
if (timer._repeat && timer._idleTimeout !== -1) {
544544
timer._idleTimeout = timer._repeat;
545545
if (start === undefined)

src/async_wrap.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
// TODO(mcollina): should this be moved in a more public space?
3232
// embedders will not be able to use this field
33-
#define CURRENT_RESOURCE_FIELD 10
33+
#define EXECUTION_RESOURCE_FIELD 10
3434

3535
using v8::Context;
3636
using v8::DontDelete;
@@ -152,7 +152,7 @@ void AsyncWrap::EmitTraceEventBefore() {
152152
void AsyncWrap::EmitBefore(Environment* env, double async_id,
153153
v8::Local<v8::Object> resource) {
154154
v8::Local<v8::Context> context = env->isolate()->GetCurrentContext();
155-
context->SetEmbedderData(CURRENT_RESOURCE_FIELD, resource);
155+
context->SetEmbedderData(EXECUTION_RESOURCE_FIELD, resource);
156156

157157
Emit(env, async_id, AsyncHooks::kBefore,
158158
env->async_hooks_before_function());
@@ -184,7 +184,7 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) {
184184
Emit(env, async_id, AsyncHooks::kAfter,
185185
env->async_hooks_after_function());
186186

187-
context->SetEmbedderData(CURRENT_RESOURCE_FIELD, v8::Null(isolate));
187+
context->SetEmbedderData(EXECUTION_RESOURCE_FIELD, v8::Null(isolate));
188188
}
189189

190190
class PromiseWrap : public AsyncWrap {
@@ -270,7 +270,7 @@ static void PromiseHook(PromiseHookType type, Local<Promise> promise,
270270

271271
// needed for async functions :/
272272
// the top level will not emit before and after
273-
env->context()->SetEmbedderData(CURRENT_RESOURCE_FIELD, wrap->object());
273+
env->context()->SetEmbedderData(EXECUTION_RESOURCE_FIELD, wrap->object());
274274
}
275275
}
276276

@@ -399,16 +399,16 @@ static void RegisterDestroyHook(const FunctionCallbackInfo<Value>& args) {
399399
p->target.SetWeak(p, AsyncWrap::WeakCallback, WeakCallbackType::kParameter);
400400
}
401401

402-
static void CurrentResource(const FunctionCallbackInfo<Value>& args) {
402+
static void GetExecutionAsyncResource(const FunctionCallbackInfo<Value>& args) {
403403
Isolate* isolate = args.GetIsolate();
404404
v8::Local<v8::Context> context = isolate->GetCurrentContext();
405-
args.GetReturnValue().Set(context->GetEmbedderData(CURRENT_RESOURCE_FIELD));
405+
args.GetReturnValue().Set(context->GetEmbedderData(EXECUTION_RESOURCE_FIELD));
406406
}
407407

408-
static void SetCurrentResource(const FunctionCallbackInfo<Value>& args) {
408+
static void SetExecutionAsyncResource(const FunctionCallbackInfo<Value>& args) {
409409
Isolate* isolate = args.GetIsolate();
410410
v8::Local<v8::Context> context = isolate->GetCurrentContext();
411-
context->SetEmbedderData(CURRENT_RESOURCE_FIELD, args[0]);
411+
context->SetEmbedderData(EXECUTION_RESOURCE_FIELD, args[0]);
412412
}
413413

414414
void AsyncWrap::GetAsyncId(const FunctionCallbackInfo<Value>& args) {
@@ -498,10 +498,11 @@ void AsyncWrap::Initialize(Local<Object> target,
498498
env->SetMethod(target, "enablePromiseHook", EnablePromiseHook);
499499
env->SetMethod(target, "disablePromiseHook", DisablePromiseHook);
500500
env->SetMethod(target, "registerDestroyHook", RegisterDestroyHook);
501-
env->SetMethod(target, "currentResource", CurrentResource);
502-
env->SetMethod(target, "setCurrentResource", SetCurrentResource);
501+
env->SetMethod(target, "executionAsyncResource", GetExecutionAsyncResource);
502+
env->SetMethod(target, "setExecutionAsyncResource",
503+
SetExecutionAsyncResource);
503504

504-
context->SetEmbedderData(CURRENT_RESOURCE_FIELD, v8::Null(isolate));
505+
context->SetEmbedderData(EXECUTION_RESOURCE_FIELD, v8::Null(isolate));
505506

506507
PropertyAttribute ReadOnlyDontDelete =
507508
static_cast<PropertyAttribute>(ReadOnly | DontDelete);

test/parallel/test-async-hooks-current-resource-await.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const common = require('../common');
44
const sleep = require('util').promisify(setTimeout);
55
const assert = require('assert');
6-
const { currentResource, createHook } = require('async_hooks');
6+
const { executionAsyncResource, createHook } = require('async_hooks');
77
const { createServer, get } = require('http');
88
const sym = Symbol('cls');
99
const id = Symbol('id');
@@ -13,7 +13,7 @@ const id = Symbol('id');
1313

1414
createHook({
1515
init(asyncId, type, triggerAsyncId, resource) {
16-
const cr = currentResource();
16+
const cr = executionAsyncResource();
1717
resource[id] = asyncId;
1818
if (cr) {
1919
resource[sym] = cr[sym];
@@ -22,9 +22,9 @@ createHook({
2222
}).enable();
2323

2424
async function handler(req, res) {
25-
currentResource()[sym] = { state: req.url };
25+
executionAsyncResource()[sym] = { state: req.url };
2626
await sleep(10);
27-
const { state } = currentResource()[sym];
27+
const { state } = executionAsyncResource()[sym];
2828
res.setHeader('content-type', 'application/json');
2929
res.end(JSON.stringify({ state }));
3030
}

test/parallel/test-async-hooks-current-resource.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const common = require('../common');
44
const assert = require('assert');
5-
const { currentResource, createHook } = require('async_hooks');
5+
const { executionAsyncResource, createHook } = require('async_hooks');
66
const { createServer, get } = require('http');
77
const sym = Symbol('cls');
88
const id = Symbol('id');
@@ -11,7 +11,7 @@ const id = Symbol('id');
1111

1212
createHook({
1313
init(asyncId, type, triggerAsyncId, resource) {
14-
const cr = currentResource();
14+
const cr = executionAsyncResource();
1515
resource[id] = asyncId;
1616
if (cr) {
1717
resource[sym] = cr[sym];
@@ -20,9 +20,9 @@ createHook({
2020
}).enable();
2121

2222
const server = createServer(function(req, res) {
23-
currentResource()[sym] = { state: req.url };
23+
executionAsyncResource()[sym] = { state: req.url };
2424
setTimeout(function() {
25-
const { state } = currentResource()[sym];
25+
const { state } = executionAsyncResource()[sym];
2626
res.setHeader('content-type', 'application/json');
2727
res.end(JSON.stringify({ state }));
2828
}, 10);

0 commit comments

Comments
 (0)