mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
0ffcb46e0f
This reverts commit 20aa0796e6
.
`main` has been failing consistenly on `kv_undelivered_test` and
`serve_test` after this upgrade.
34 lines
985 B
TypeScript
34 lines
985 B
TypeScript
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
import { assertEquals } from "../../../test_util/std/testing/asserts.ts";
|
|
|
|
Deno.test("BroadcastChannel worker", async () => {
|
|
const intercom = new BroadcastChannel("intercom");
|
|
let count = 0;
|
|
|
|
const url = import.meta.resolve(
|
|
"../testdata/workers/broadcast_channel.ts",
|
|
);
|
|
const worker = new Worker(url, { type: "module", name: "worker" });
|
|
worker.onmessage = () => intercom.postMessage(++count);
|
|
|
|
const { promise, resolve } = Promise.withResolvers<void>();
|
|
|
|
intercom.onmessage = function (e) {
|
|
assertEquals(count, e.data);
|
|
if (count < 42) {
|
|
intercom.postMessage(++count);
|
|
} else {
|
|
worker.terminate();
|
|
intercom.close();
|
|
resolve();
|
|
}
|
|
};
|
|
|
|
await promise;
|
|
});
|
|
|
|
Deno.test("BroadcastChannel immediate close after post", () => {
|
|
const bc = new BroadcastChannel("internal_notification");
|
|
bc.postMessage("New listening connected!");
|
|
bc.close();
|
|
});
|