/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
benchmark/process/handled-rejections.js
43 строки
1 KB
Gürgün Dayıoğlu
process: optimize asyncHandledRejections by using FixedQueue
02 янв 2026, 14:40
Не верифицирован
02 янв 2026, 14:40
012bf70
Код
Авторство
О чём код?
'use strict'; const common = require('../common.js'); // Benchmarks the throughput of processing many promise rejections that are // initially unhandled, get warned, and then handled asynchronously, exercising // asyncHandledRejections + processPromiseRejections. // // Note: This benchmark uses --unhandled-rejections=warn to avoid crashing // when promises are temporarily unhandled. const bench = common.createBenchmark(main, { n: [1e4, 5e4, 1e5], }, { flags: ['--unhandled-rejections=warn'], }); function main({ n }) { const rejections = []; // Suppress warning output during the benchmark process.removeAllListeners('warning'); for (let i = 0; i < n; i++) { rejections.push(Promise.reject(i)); } // Wait for them to be processed as unhandled and warned. setImmediate(() => { setImmediate(() => { bench.start(); for (let i = 0; i < n; i++) { rejections[i].catch(() => {}); } // Let processPromiseRejections drain asyncHandledRejections. setImmediate(() => { bench.end(n); }); }); }); }