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" },
|
|
|
|
);
|
2021-05-18 11:24:01 -04:00
|
|
|
worker.onmessage = (_e): void => {
|
2021-02-23 07:08:50 -05:00
|
|
|
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();
|