(
payload: Record<string, unknown>,
timeoutMs = 5_000,
)
| 233 | } |
| 234 | |
| 235 | private sendRequest( |
| 236 | payload: Record<string, unknown>, |
| 237 | timeoutMs = 5_000, |
| 238 | ): Promise<Record<string, unknown>> { |
| 239 | const reqId = String(++this.reqCounter); |
| 240 | const envelope = { request: { ...payload, request_id: reqId } }; |
| 241 | return new Promise((resolve, reject) => { |
| 242 | const timer = setTimeout(() => { |
| 243 | this.pendingRequests.delete(reqId); |
| 244 | reject(new CliError( |
| 245 | `Valdi daemon did not respond (port ${(this.socket.remotePort ?? '?')}).\n` + |
| 246 | `Is the hot-reloader actually running and connected?`, |
| 247 | )); |
| 248 | }, timeoutMs); |
| 249 | this.pendingRequests.set(reqId, { |
| 250 | resolve: (v) => { clearTimeout(timer); resolve(v); }, |
| 251 | reject: (e) => { clearTimeout(timer); reject(e); }, |
| 252 | }); |
| 253 | this.socket.write(encodePacket(envelope), (err) => { |
| 254 | if (err) { |
| 255 | clearTimeout(timer); |
| 256 | this.pendingRequests.delete(reqId); |
| 257 | reject(err); |
| 258 | } |
| 259 | }); |
| 260 | }); |
| 261 | } |
| 262 | |
| 263 | private nextMsgId(): string { |
| 264 | return String(++this.msgCounter); |
nothing calls this directly
no test coverage detected