From cb16aabd15d0b56af4d266034a0b23c02559099f 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. Backport-PR-URL: https://github.com/nodejs/node/pull/32301 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 61bfa47c13d702..684e183b853234 100644 --- a/src/env.cc +++ b/src/env.cc @@ -687,13 +687,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);