1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-15 16:43:44 -05:00
denoland-deno/cli/tests/workers/bench_large_message.ts
Tim Ramlot 635253bd3a
feat(runtime/worker): Structured cloning worker message passing (#9323)
This commit upgrade "Worker.postMessage()" implementation to use 
structured clone algorithm instead of non-spec compliant JSON serialization.
2021-05-11 21:09:09 +02:00

31 lines
658 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();