Skip to content

Commit

Permalink
src: simplify native immediate queue running
Browse files Browse the repository at this point in the history
Make `SetImmediate()` behave more like `process.nextTick()`
(which matches how we use it) by also running tasks that have been
added during previous `SetImmediate()` calls.

PR-URL: #31502
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
addaleax authored and codebytere committed Feb 17, 2020
1 parent 07525c3 commit ef4d081
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -688,13 +688,11 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
native_immediates_.ConcatMove(std::move(native_immediates_threadsafe_));
}

NativeImmediateQueue queue;
queue.ConcatMove(std::move(native_immediates_));

auto drain_list = [&]() {
TryCatchScope try_catch(this);
DebugSealHandleScope seal_handle_scope(isolate());
while (std::unique_ptr<NativeImmediateCallback> head = queue.Shift()) {
while (std::unique_ptr<NativeImmediateCallback> head =
native_immediates_.Shift()) {
if (head->is_refed())
ref_count++;

Expand All @@ -712,7 +710,7 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
}
return false;
};
while (queue.size() > 0 && drain_list()) {}
while (drain_list()) {}

immediate_info()->ref_count_dec(ref_count);

Expand Down

0 comments on commit ef4d081

Please sign in to comment.