mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
timers: allow Immediates to be unrefed
Refactor Immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Document the new `immediate.ref()` and `immediate.unref()` methods. Add SetImmediateUnref on the C++ side. Backport-PR-URL: https://github.com/nodejs/node/pull/19265 PR-URL: https://github.com/nodejs/node/pull/18139 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
84e0a03727
commit
e15f57745d
1 file changed
+9
@@ -24,6 +24,15 @@ void* SetImmediate(napi_env env, T&& cb) {
|
||||
|
||||
assert(cb() != nullptr);
|
||||
});
|
||||
// Idle handle is needed only to stop the event loop from blocking in poll.
|
||||
uv_idle_t* idle = new uv_idle_t;
|
||||
uv_idle_init(loop, idle);
|
||||
uv_idle_start(idle, [](uv_idle_t* idle) {
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(idle), [](uv_handle_t* handle) {
|
||||
delete reinterpret_cast<uv_check_t*>(handle);
|
||||
});
|
||||
});
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user