Skip to content

Commit c12d109

Browse files
authored
fix: Restored compatibility with cronometro. (#1406)
1 parent f3f7f80 commit c12d109

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

benchmarks/benchmark.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict'
22

3-
const cronometro = require('cronometro')
4-
const { Writable } = require('stream')
53
const http = require('http')
64
const os = require('os')
75
const path = require('path')
86
const { table } = require('table')
7+
const { Writable } = require('stream')
98
const { WritableStream } = require('stream/web')
9+
const { isMainThread } = require('worker_threads')
1010

1111
const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..')
1212

@@ -258,19 +258,29 @@ if (process.env.PORT) {
258258
}
259259
}
260260

261-
cronometro(
262-
experiments,
263-
{
264-
iterations,
265-
errorThreshold,
266-
print: false
267-
},
268-
(err, results) => {
269-
if (err) {
270-
throw err
261+
async function main () {
262+
const { cronometro } = await import('cronometro')
263+
264+
cronometro(
265+
experiments,
266+
{
267+
iterations,
268+
errorThreshold,
269+
print: false
270+
},
271+
(err, results) => {
272+
if (err) {
273+
throw err
274+
}
275+
276+
console.log(printResults(results))
277+
dispatcher.destroy()
271278
}
279+
)
280+
}
272281

273-
console.log(printResults(results))
274-
dispatcher.destroy()
275-
}
276-
)
282+
if (isMainThread) {
283+
main()
284+
} else {
285+
module.exports = main
286+
}

0 commit comments

Comments
 (0)