mirror of
https://github.com/denoland/deno.git
synced 2024-10-30 09:08:00 -04:00
dccf5e0c5c
This commit rewrites "JsRuntime::poll" function to fix a corner case that might caused "overflown_response" to be overwritten by other overflown response. The logic has been changed to allow returning multiple overflown response alongside responses from shared queue.
35 lines
783 B
TypeScript
35 lines
783 B
TypeScript
// Copyright 2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
// deno-lint-ignore-file
|
|
|
|
import { deferred } from "../../test_util/std/async/deferred.ts";
|
|
|
|
function oneWorker(i: any): Promise<void> {
|
|
return new Promise<void>((resolve) => {
|
|
let countDown = 10;
|
|
const worker = new Worker(
|
|
new URL("workers/large_message_worker.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(): Promise<any> {
|
|
let promises = [];
|
|
for (let i = 0; i < 50; i++) {
|
|
promises.push(oneWorker(i));
|
|
}
|
|
|
|
return Promise.all(promises);
|
|
}
|
|
|
|
bench();
|