mirror of
https://github.com/denoland/deno.git
synced 2024-10-31 09:14:20 -04:00
31 lines
659 B
TypeScript
31 lines
659 B
TypeScript
// 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(
|
|
new URL("worker_large_message.js", import.meta.url).href,
|
|
{ type: "module" },
|
|
);
|
|
worker.onmessage = (_e): void => {
|
|
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();
|