Concepts
Bounded WebSocket send policy
Application policy for limiting queued outbound bytes; not a native WebSocket backpressure API.
Formal Syntax & Structure
javascript syntaxjavascript
socket.readyState === WebSocket.OPEN && socket.bufferedAmount + bytes <= limitReturn Value
boolean
Application policy for limiting queued outbound bytes; not a native WebSocket backpressure API.
Working Example
Example Snippetjavascript
(async () => {const canSend=(state,queued,bytes,limit)=>state===WebSocket.OPEN&&queued+bytes<=limit;console.log(JSON.stringify([canSend(1,8,2,10),canSend(1,8,3,10),canSend(0,0,1,10)]));})()