Aller au contenu
#0798
Exec

The function that holds a thousand sockets

Your product ships a live dashboard. Orders stream in; every open tab should see them land. You write one exec script: // @mode worker, // @websocket. The script answers plain HTTP with the dashboard page, and the same file holds the sockets: ws.message handles incoming, ws.broadcast pushes to every connected client, and ws.connections.size says 1,214 tabs are watching.

On a fresh-VM-per-request platform, a socket has nowhere to live: the VM that accepted it is gone before the next frame. So you bolt on a managed socket service and a second bill.

Here the persistent VM is the socket server. One file, one URL, HTTP in the front, WebSocket out the back.

A socket needs somewhere to live. Worker mode is somewhere.