(conn: Conn, timeoutMs: number)
| 173 | } |
| 174 | |
| 175 | function receive(conn: Conn, timeoutMs: number): Promise<WsFrame> { |
| 176 | return new Promise((resolve, reject) => { |
| 177 | if (conn.queue.length > 0) { |
| 178 | resolve(conn.queue.shift()!); |
| 179 | return; |
| 180 | } |
| 181 | const t = setTimeout(() => { |
| 182 | const idx = conn.waiters.indexOf(waiter); |
| 183 | if (idx >= 0) conn.waiters.splice(idx, 1); |
| 184 | reject(new Error(`no message in ${timeoutMs}ms`)); |
| 185 | }, timeoutMs); |
| 186 | const waiter = (frame: WsFrame): void => { |
| 187 | clearTimeout(t); |
| 188 | resolve(frame); |
| 189 | }; |
| 190 | conn.waiters.push(waiter); |
| 191 | }); |
| 192 | } |
| 193 | |
| 194 | async function receiveType( |
| 195 | conn: Conn, |
no test coverage detected