mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 03:18:53 +00:00
* Add a zig fmt action * add failing file * Setup prettier better * Update prettier-fmt.yml * Fail on error * Update prettier-fmt.yml * boop * boop2 * tar.gz * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * boop * Update prettier-fmt.yml * tag * newlines * multiline * fixup * Update zig-fmt.yml * update it * fixup * both * w * Update prettier-fmt.yml * prettier all the things * Update package.json * zig fmt * ❌ ✅ * bump * . * quotes * fix prettier ignore * once more * Update prettier-fmt.yml * Update fallback.ts * consistentcy --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
// See ./README.md for instructions on how to run this benchmark.
|
|
const CLIENTS_TO_WAIT_FOR = parseInt(process.env.CLIENTS_COUNT || "", 10) || 16;
|
|
var remainingClients = CLIENTS_TO_WAIT_FOR;
|
|
const COMPRESS = process.env.COMPRESS === "1";
|
|
const port = process.PORT || 4001;
|
|
|
|
const server = Bun.serve({
|
|
port: port,
|
|
websocket: {
|
|
open(ws) {
|
|
ws.subscribe("room");
|
|
|
|
remainingClients--;
|
|
console.log(`${ws.data.name} connected (${remainingClients} remain)`);
|
|
|
|
if (remainingClients === 0) {
|
|
console.log("All clients connected");
|
|
setTimeout(() => {
|
|
console.log('Starting benchmark by sending "ready" message');
|
|
ws.publishText("room", `ready`);
|
|
}, 100);
|
|
}
|
|
},
|
|
message(ws, msg) {
|
|
const out = `${ws.data.name}: ${msg}`;
|
|
if (ws.publishText("room", out) !== out.length) {
|
|
throw new Error("Failed to publish message");
|
|
}
|
|
},
|
|
close(ws) {
|
|
remainingClients++;
|
|
},
|
|
|
|
perMessageDeflate: false,
|
|
},
|
|
|
|
fetch(req, server) {
|
|
if (
|
|
server.upgrade(req, {
|
|
data: {
|
|
name: new URL(req.url).searchParams.get("name") || "Client #" + (CLIENTS_TO_WAIT_FOR - remainingClients),
|
|
},
|
|
})
|
|
)
|
|
return;
|
|
|
|
return new Response("Error");
|
|
},
|
|
});
|
|
|
|
console.log(`Waiting for ${remainingClients} clients to connect...\n`, ` http://${server.hostname}:${port}/`);
|