MCPcopy Create free account
hub / github.com/Snapchat/Valdi / sendRequest

Method sendRequest

npm_modules/cli/src/utils/daemonClient.ts:235–261  ·  view source on GitHub ↗
(
    payload: Record<string, unknown>,
    timeoutMs = 5_000,
  )

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls 9

rejectFunction · 0.85
encodePacketFunction · 0.85
deleteMethod · 0.65
setMethod · 0.65
writeMethod · 0.65
StringClass · 0.50
setTimeoutFunction · 0.50
clearTimeoutFunction · 0.50
resolveFunction · 0.50

Tested by

no test coverage detected