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(
|
2022-07-20 10:56:53 -04:00
|
|
|
import.meta.resolve("./worker_large_message.js"),
|
2021-02-23 07:08:50 -05:00
|
|
|
{ type: "module" },
|
|
|
|
);
|
2021-08-05 07:08:58 -04:00
|
|
|
worker.onmessage = (_e) => {
|
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();
|