diff --git a/src/async-wrap.cc b/src/async-wrap.cc index 7ca3f6c604..913ff9e7c8 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -455,7 +455,8 @@ void AsyncWrap::ClearAsyncIdStack(const FunctionCallbackInfo& args) { void AsyncWrap::AsyncReset(const FunctionCallbackInfo& 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); } @@ -577,7 +578,8 @@ void LoadAsyncWrapperInfo(Environment* env) { AsyncWrap::AsyncWrap(Environment* env, Local object, - ProviderType provider) + ProviderType provider, + double execution_async_id) : BaseObject(env, object), provider_type_(provider) { CHECK_NE(provider, PROVIDER_NONE); @@ -587,7 +589,7 @@ AsyncWrap::AsyncWrap(Environment* env, persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider); // Use AsyncReset() call to execute the init() callbacks. - AsyncReset(); + AsyncReset(execution_async_id); } @@ -603,7 +605,7 @@ AsyncWrap::AsyncWrap(Environment* env, persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider_type_); // Use AsyncReset() call to execute the init() callbacks. - AsyncReset(silent); + AsyncReset(-1, silent); } @@ -615,8 +617,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; diff --git a/src/async-wrap.h b/src/async-wrap.h index 0e0415da17..d24eb0d46d 100644 --- a/src/async-wrap.h +++ b/src/async-wrap.h @@ -94,7 +94,8 @@ class AsyncWrap : public BaseObject { AsyncWrap(Environment* env, v8::Local object, - ProviderType provider); + ProviderType provider, + double execution_async_id = -1); virtual ~AsyncWrap(); @@ -132,7 +133,7 @@ class AsyncWrap : public BaseObject { inline double get_trigger_async_id() const; - void AsyncReset(bool silent = false); + void AsyncReset(double execution_async_id = -1, bool silent = false); // Only call these within a valid HandleScope. v8::MaybeLocal MakeCallback(const v8::Local cb,