Skip to content

Commit

Permalink
Introduce a new GetCurrentEventLoop function that returns the current…
Browse files Browse the repository at this point in the history
… event loop and use it in AsyncWorker and AsyncProgressWorker
  • Loading branch information
rpetrich authored and kkoopa committed Jul 1, 2018
1 parent 77d0fca commit b4911b0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,14 @@ class AsyncResource {
#endif
};

inline uv_loop_t* GetCurrentEventLoop() {
#if NODE_MODULE_VERSION > NODE_9_0_MODULE_VERSION
return node::GetCurrentEventLoop(v8::Isolate::GetCurrent());
#else
return uv_default_loop();
#endif
}

//============ =================================================================

/* node 0.12 */
Expand Down Expand Up @@ -1899,7 +1907,7 @@ inline MaybeLocal<v8::Value> Call(
const char* resource_name = "nan:AsyncBareProgressWorkerBase")
: AsyncWorker(callback_, resource_name) {
uv_async_init(
uv_default_loop()
GetCurrentEventLoop()
, &async
, AsyncProgress_
);
Expand Down Expand Up @@ -2161,7 +2169,7 @@ inline void AsyncExecuteComplete (uv_work_t* req) {

inline void AsyncQueueWorker (AsyncWorker* worker) {
uv_queue_work(
uv_default_loop()
GetCurrentEventLoop()
, &worker->request
, AsyncExecute
, reinterpret_cast<uv_after_work_cb>(AsyncExecuteComplete)
Expand Down

0 comments on commit b4911b0

Please sign in to comment.