diff options
Diffstat (limited to 'ext/node/benchmarks/child_process_ipc.mjs')
-rw-r--r-- | ext/node/benchmarks/child_process_ipc.mjs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ext/node/benchmarks/child_process_ipc.mjs b/ext/node/benchmarks/child_process_ipc.mjs index 0486972dc..39377cd8c 100644 --- a/ext/node/benchmarks/child_process_ipc.mjs +++ b/ext/node/benchmarks/child_process_ipc.mjs @@ -5,10 +5,20 @@ import { setImmediate } from "node:timers"; if (process.env.CHILD) { const len = +process.env.CHILD; const msg = ".".repeat(len); + let waiting = false; const send = () => { - while (process.send(msg)); + while ( + process.send(msg, undefined, undefined, (_e) => { + if (waiting) { + waiting = false; + setImmediate(send); + } + }) + ); // Wait: backlog of unsent messages exceeds threshold - setImmediate(send); + // once the message is sent, the callback will be called + // and we'll resume + waiting = true; }; send(); } else { |