From 78743f8e3912fa04670ceab5365f081b3079507b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 25 Jan 2020 02:02:57 +0100 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/31502 Reviewed-By: Yongsheng Zhang Reviewed-By: David Carlier Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Minwoo Jung --- src/env.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/env.cc b/src/env.cc index 19c29c2fcab950..36b41c5fac56c4 100644 --- a/src/env.cc +++ b/src/env.cc @@ -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 head = queue.Shift()) { + while (std::unique_ptr head = + native_immediates_.Shift()) { if (head->is_refed()) ref_count++; @@ -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);