MCPcopy Create free account
hub / github.com/alex8088/electron-vite / sendRequest

Method sendRequest

src/bytecodeCompiler.ts:119–141  ·  view source on GitHub ↗
(cmd: string, args: unknown[])

Source from the content-addressed store, hash-verified

117 }
118
119 private sendRequest(cmd: string, args: unknown[]): Promise<unknown> {
120 const ps = this.ps
121 if (!ps?.connected) return Promise.reject(new Error('Electron IPC is not connected'))
122 const invocationId = this.invocationId++
123 return new Promise((resolve, reject) => {
124 const fail = (error: Error): void => {
125 const pending = this.rpcMap.get(invocationId)
126 if (!pending) return
127 clearTimeout(pending.timer)
128 this.rpcMap.delete(invocationId)
129 reject(this.withStderr(error))
130 }
131 const timer = setTimeout(() => fail(new Error('Electron RPC timed out: ' + cmd)), RPC_TIMEOUT)
132 this.rpcMap.set(invocationId, { resolve, reject, timer })
133 try {
134 ps.send({ type: 'request', invocationId, cmd, args }, error => {
135 if (error) fail(error)
136 })
137 } catch (error) {
138 fail(error instanceof Error ? error : new Error(String(error)))
139 }
140 })
141 }
142
143 private rejectPending(error: Error): void {
144 this.ready = false

Callers 2

initializeMethod · 0.95
requestMethod · 0.95

Calls 1

failFunction · 0.85

Tested by

no test coverage detected