2021-02-23 07:08:50 -05:00
|
|
|
// Copyright 2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2021-05-11 15:09:09 -04:00
|
|
|
function oneWorker(i: number) {
|
2021-02-23 07:08:50 -05:00
|
|
|
return new Promise<void>((resolve) => {
|
|
|
|
let countDown = 10;
|
|
|
|
const worker = new Worker(
|
2021-05-11 15:09:09 -04:00
|
|
|
new URL("worker_large_message.js", import.meta.url).href,
|
2021-02-23 07:08:50 -05:00
|
|
|
{ type: "module" },
|
|
|
|
);
|
|
|
|
worker.onmessage = (e): void => {
|
|
|
|
if (countDown > 0) {
|
|
|
|
countDown--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
worker.terminate();
|
|
|
|
resolve();
|
|
|
|
};
|
|
|
|
worker.postMessage("hi " + i);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-11 15:09:09 -04:00
|
|
|
function bench() {
|
|
|
|
const promises = [];
|
2021-02-23 07:08:50 -05:00
|
|
|
for (let i = 0; i < 50; i++) {
|
|
|
|
promises.push(oneWorker(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.all(promises);
|
|
|
|
}
|
|
|
|
|
|
|
|
bench();
|