src: limit foreground tasks draining loop
Foreground tasks that repost themselves can force the draining loop to run indefinitely long without giving other tasks chance to run.
This limits the foreground task draining loop to run only the tasks that were in the tasks queue at the beginning of the loop.
Fixes: https://github.com/nodejs/node/issues/19937
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines