1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-11 01:58:05 -05:00
denoland-deno/cli/tests/testdata/workers/bench_large_message.ts

32 lines
645 B
TypeScript
Raw Normal View History

// Copyright 2020 the Deno authors. All rights reserved. MIT license.
function oneWorker(i: number) {
return new Promise<void>((resolve) => {
let countDown = 10;
const worker = new Worker(
import.meta.resolve("./worker_large_message.js"),
{ type: "module" },
);
worker.onmessage = (_e) => {
if (countDown > 0) {
countDown--;
return;
}
worker.terminate();
resolve();
};
worker.postMessage("hi " + i);
});
}
function bench() {
const promises = [];
for (let i = 0; i < 50; i++) {
promises.push(oneWorker(i));
}
return Promise.all(promises);
}
bench();