-
- Notifications
You must be signed in to change notification settings - Fork 33.8k
allow passing custom async_id to node::AsyncWrap::AsyncWrap #14208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4321206 44dc449 d28d20c e1eae3c 2b9b46c File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -243,7 +243,7 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) { | |
| class PromiseWrap : public AsyncWrap { | ||
| public: | ||
| PromiseWrap(Environment* env, Local<Object> object, bool silent) | ||
| : AsyncWrap(env, object, PROVIDER_PROMISE, silent) { | ||
| : AsyncWrap(env, object, silent) { | ||
| MakeWeak(this); | ||
| } | ||
| size_t self_size() const override { return sizeof(*this); } | ||
| | @@ -451,7 +451,8 @@ void AsyncWrap::ClearAsyncIdStack(const FunctionCallbackInfo<Value>& args) { | |
| void AsyncWrap::AsyncReset(const FunctionCallbackInfo<Value>& args) { | ||
| AsyncWrap* wrap; | ||
| ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | ||
| wrap->AsyncReset(); | ||
| double execution_async_id = args[0]->IsNumber() ? args[0]->NumberValue() : -1; | ||
| wrap->AsyncReset(execution_async_id); | ||
| } | ||
| | ||
| | ||
| | @@ -574,7 +575,7 @@ void LoadAsyncWrapperInfo(Environment* env) { | |
| AsyncWrap::AsyncWrap(Environment* env, | ||
| Local<Object> object, | ||
| ProviderType provider, | ||
| bool silent) | ||
| double execution_async_id) | ||
| : BaseObject(env, object), | ||
| provider_type_(provider) { | ||
| CHECK_NE(provider, PROVIDER_NONE); | ||
| | @@ -584,7 +585,23 @@ AsyncWrap::AsyncWrap(Environment* env, | |
| persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider); | ||
| | ||
| // Use AsyncReset() call to execute the init() callbacks. | ||
| AsyncReset(silent); | ||
| AsyncReset(execution_async_id); | ||
| } | ||
| | ||
| | ||
| // This is specifically used by the PromiseWrap constructor. | ||
| AsyncWrap::AsyncWrap(Environment* env, | ||
| Local<Object> object, | ||
| bool silent) | ||
| : BaseObject(env, object), | ||
| provider_type_(PROVIDER_PROMISE) { | ||
| ||
| CHECK_GE(object->InternalFieldCount(), 1); | ||
| | ||
| // Shift provider value over to prevent id collision. | ||
| persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider_type_); | ||
| | ||
| // Use AsyncReset() call to execute the init() callbacks. | ||
| AsyncReset(-1, silent); | ||
| } | ||
| | ||
| | ||
| | @@ -596,8 +613,9 @@ AsyncWrap::~AsyncWrap() { | |
| // Generalized call for both the constructor and for handles that are pooled | ||
| // and reused over their lifetime. This way a new uid can be assigned when | ||
| // the resource is pulled out of the pool and put back into use. | ||
| void AsyncWrap::AsyncReset(bool silent) { | ||
| async_id_ = env()->new_async_id(); | ||
| void AsyncWrap::AsyncReset(double execution_async_id, bool silent) { | ||
| async_id_ = | ||
| execution_async_id == -1 ? env()->new_async_id() : execution_async_id; | ||
| trigger_async_id_ = env()->get_init_trigger_async_id(); | ||
| | ||
| if (silent) return; | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -5,6 +5,11 @@ const assert = require('assert'); | |
| const async_hooks = require('async_hooks'); | ||
| const binding = require(`./build/${common.buildType}/binding`); | ||
| | ||
| if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) { | ||
| ||
| common.skip('cannot test with env var NODE_TEST_WITH_ASYNC_HOOKS'); | ||
| return; | ||
| } | ||
| | ||
| // Baseline to make sure the internal field isn't being set. | ||
| assert.strictEqual( | ||
| binding.getPromiseField(Promise.resolve(1)), | ||
| | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$(PYTHON) tools/test.py --mode=release $(CI_ASYNC_HOOKS)?