Skip to content

Commit e15f577

Browse files
apapirovskiMylesBorins
authored andcommitted
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: #19265 PR-URL: #18139 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 84e0a03 commit e15f577

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

test/addons-napi/test_uv_loop/test_uv_loop.cc

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ void* SetImmediate(napi_env env, T&& cb) {
2424

2525
assert(cb() != nullptr);
2626
});
27+
// Idle handle is needed only to stop the event loop from blocking in poll.
28+
uv_idle_t* idle = new uv_idle_t;
29+
uv_idle_init(loop, idle);
30+
uv_idle_start(idle, [](uv_idle_t* idle) {
31+
uv_close(reinterpret_cast<uv_handle_t*>(idle), [](uv_handle_t* handle) {
32+
delete reinterpret_cast<uv_check_t*>(handle);
33+
});
34+
});
35+
2736
return nullptr;
2837
}
2938

0 commit comments

Comments
 (0)