Skip to content

Commit

Permalink
timers: allow Immediates to be unrefed
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
apapirovski authored and MylesBorins committed May 1, 2018
1 parent 84e0a03 commit e15f577
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/addons-napi/test_uv_loop/test_uv_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

1 comment on commit e15f577

@MylesBorins

This comment was marked as outdated.

Please sign in to comment.