Skip to content

Commit cb16aab

Browse files
addaleaxMylesBorins
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. Backport-PR-URL: #32301 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 87cfbb2 commit cb16aab

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
@@ -687,13 +687,11 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
687687
native_immediates_.ConcatMove(std::move(native_immediates_threadsafe_));
688688
}
689689

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

@@ -709,7 +707,7 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) {
709707
}
710708
return false;
711709
};
712-
while (queue.size() > 0 && drain_list()) {}
710+
while (drain_list()) {}
713711

714712
immediate_info()->ref_count_dec(ref_count);
715713

0 commit comments

Comments
 (0)