From 9cf352553576ec3cf003a003da7e236772cd245e Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 17 Nov 2017 22:16:43 +0100 Subject: n-api: add helper for addons to get the event loop Add a utility functions for addons to use when they need a reference to the current event loop. While the libuv API is not directly part of N-API, it provides a quite stable C API as well, and is tightly integrated with Node itself. As a particular use case, without access to the event loop it is hard to do something interesting from inside a N-API finalizer function, since calls into JS and therefore virtually all other N-API functions are not allowed. PR-URL: https://github.com/nodejs/node/pull/17109 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig --- src/node_api.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/node_api.h') diff --git a/src/node_api.h b/src/node_api.h index a3a07a6467..8e5eef8a47 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -14,6 +14,8 @@ #include #include "node_api_types.h" +struct uv_loop_s; // Forward declaration. + #ifdef _WIN32 #ifdef BUILDING_NODE_EXTENSION #ifdef EXTERNAL_NAPI @@ -581,6 +583,10 @@ NAPI_EXTERN napi_status napi_run_script(napi_env env, napi_value script, napi_value* result); +// Return the current libuv event loop for a given environment +NAPI_EXTERN napi_status napi_get_uv_event_loop(napi_env env, + struct uv_loop_s** loop); + EXTERN_C_END #endif // SRC_NODE_API_H_ -- cgit v1.2.3