Skip to content

Commit ef4d081

Browse files
addaleaxcodebytere
authored andcommitted
src: simplify native immediate queue running
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>
1 parent 07525c3 commit ef4d081

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/env.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,11 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
688688
native_immediates_.ConcatMove(std::move(native_immediates_threadsafe_));
689689
}
690690

691-
NativeImmediateQueue queue;
692-
queue.ConcatMove(std::move(native_immediates_));
693-
694691
auto drain_list = [&]() {
695692
TryCatchScope try_catch(this);
696693
DebugSealHandleScope seal_handle_scope(isolate());
697-
while (std::unique_ptr<NativeImmediateCallback> head = queue.Shift()) {
694+
while (std::unique_ptr<NativeImmediateCallback> head =
695+
native_immediates_.Shift()) {
698696
if (head->is_refed())
699697
ref_count++;
700698

@@ -712,7 +710,7 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
712710
}
713711
return false;
714712
};
715-
while (queue.size() > 0 && drain_list()) {}
713+
while (drain_list()) {}
716714

717715
immediate_info()->ref_count_dec(ref_count);
718716

0 commit comments

Comments
 (0)