cork

Bun

Symbol

ServerWebSocket.cork

cork<T = unknown>(callback: (ws: ServerWebSocket<T>) => T): T

Batches send() and publish() operations, which makes it faster to send data.

The message, open, and drain callbacks are automatically corked, so you only need to call this if you are sending messages outside of those callbacks or in async functions.

@param callback

The callback to run.

ws.cork((ctx) => {
  ctx.send("These messages");
  ctx.sendText("are sent");
  ctx.sendBinary(new TextEncoder().encode("together!"));
});