From 6368343b6e671b91a57eed5e0d667dc5db99a559 Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Tue, 3 May 2022 15:51:57 +0200 Subject: [PATCH] fix: Restored compatibility with cronometro. (#1406) --- benchmarks/benchmark.js | 42 +++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/benchmarks/benchmark.js b/benchmarks/benchmark.js index c321a5000cb..8b1caa666f7 100644 --- a/benchmarks/benchmark.js +++ b/benchmarks/benchmark.js @@ -1,12 +1,12 @@ 'use strict' -const cronometro = require('cronometro') -const { Writable } = require('stream') const http = require('http') const os = require('os') const path = require('path') const { table } = require('table') +const { Writable } = require('stream') const { WritableStream } = require('stream/web') +const { isMainThread } = require('worker_threads') const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..') @@ -258,19 +258,29 @@ if (process.env.PORT) { } } -cronometro( - experiments, - { - iterations, - errorThreshold, - print: false - }, - (err, results) => { - if (err) { - throw err +async function main () { + const { cronometro } = await import('cronometro') + + cronometro( + experiments, + { + iterations, + errorThreshold, + print: false + }, + (err, results) => { + if (err) { + throw err + } + + console.log(printResults(results)) + dispatcher.destroy() } + ) +} - console.log(printResults(results)) - dispatcher.destroy() - } -) +if (isMainThread) { + main() +} else { + module.exports = main +}