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 committed Jan 27, 2020
1 parent a5d4a39 commit 78743f8
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 @@ -685,13 +685,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 @@ -709,7 +707,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 78743f8

Please sign in to comment.