@@ -187,7 +187,7 @@ export function clearBenchmarks({
187
187
*/
188
188
export async function runBenchmarks (
189
189
{ only = / [ ^ \s ] / , skip = / ^ \s * $ / , silent } : BenchmarkRunOptions = { } ,
190
- progressCb ?: ( progress : BenchmarkRunProgress ) => void
190
+ progressCb ?: ( progress : BenchmarkRunProgress ) => void | Promise < void >
191
191
) : Promise < BenchmarkRunResult > {
192
192
// Filtering candidates by the "only" and "skip" constraint
193
193
const benchmarks : BenchmarkDefinition [ ] = candidates . filter (
@@ -213,7 +213,7 @@ export async function runBenchmarks(
213
213
} ;
214
214
215
215
// Publish initial progress data
216
- publishProgress ( progress , ProgressState . BenchmarkingStart , progressCb ) ;
216
+ await publishProgress ( progress , ProgressState . BenchmarkingStart , progressCb ) ;
217
217
218
218
if ( ! silent ) {
219
219
console . log (
@@ -243,7 +243,7 @@ export async function runBenchmarks(
243
243
// Init the progress of the running benchmark
244
244
progress . running = { name, runsCount : runs , measuredRunsMs : [ ] } ;
245
245
// Publish starting of a benchmark
246
- publishProgress ( progress , ProgressState . BenchStart , progressCb ) ;
246
+ await publishProgress ( progress , ProgressState . BenchStart , progressCb ) ;
247
247
248
248
// Trying benchmark.func
249
249
let result = "" ;
@@ -267,7 +267,11 @@ export async function runBenchmarks(
267
267
// Adding partial result
268
268
progress . running . measuredRunsMs . push ( measuredMs ) ;
269
269
// Publish partial benchmark results
270
- publishProgress ( progress , ProgressState . BenchPartialResult , progressCb ) ;
270
+ await publishProgress (
271
+ progress ,
272
+ ProgressState . BenchPartialResult ,
273
+ progressCb
274
+ ) ;
271
275
272
276
// Resetting the benchmark clock
273
277
clock . start = clock . stop = NaN ;
@@ -288,7 +292,11 @@ export async function runBenchmarks(
288
292
// Clear currently running
289
293
delete progress . running ;
290
294
// Publish results of the benchmark
291
- publishProgress ( progress , ProgressState . BenchResult , progressCb ) ;
295
+ await publishProgress (
296
+ progress ,
297
+ ProgressState . BenchResult ,
298
+ progressCb
299
+ ) ;
292
300
break ;
293
301
}
294
302
}
@@ -317,7 +325,7 @@ export async function runBenchmarks(
317
325
// Indicate finished running
318
326
delete progress . queued ;
319
327
// Publish final result in Cb too
320
- publishProgress ( progress , ProgressState . BenchmarkingEnd , progressCb ) ;
328
+ await publishProgress ( progress , ProgressState . BenchmarkingEnd , progressCb ) ;
321
329
322
330
if ( ! silent ) {
323
331
// Closing results
@@ -340,12 +348,12 @@ export async function runBenchmarks(
340
348
return benchmarkRunResult ;
341
349
}
342
350
343
- function publishProgress (
351
+ async function publishProgress (
344
352
progress : BenchmarkRunProgress ,
345
353
state : ProgressState ,
346
- progressCb ?: ( progress : BenchmarkRunProgress ) => void
347
- ) : void {
348
- progressCb && progressCb ( cloneProgressWithState ( progress , state ) ) ;
354
+ progressCb ?: ( progress : BenchmarkRunProgress ) => void | Promise < void >
355
+ ) : Promise < void > {
356
+ progressCb && ( await progressCb ( cloneProgressWithState ( progress , state ) ) ) ;
349
357
}
350
358
351
359
function cloneProgressWithState (
0 commit comments