MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / invokeMainRequest

Function invokeMainRequest

desktop/runtime-host/main-request-client.ts:34–58  ·  view source on GitHub ↗
(
  name: TName,
  payload: RuntimeHostMainRequestMap[TName],
)

Source from the content-addressed store, hash-verified

32}
33
34export async function invokeMainRequest<TName extends RuntimeHostMainRequestName>(
35 name: TName,
36 payload: RuntimeHostMainRequestMap[TName],
37): Promise<RuntimeHostMainResponseMap[TName]> {
38 if (!process.send) {
39 throw new Error(`Cannot invoke main request ${name}: runtime host IPC is unavailable.`)
40 }
41
42 const id = randomUUID()
43 const result = new Promise<RuntimeHostMainResponseMap[TName]>((resolve, reject) => {
44 const timeout = setTimeout(() => {
45 pendingMainRequests.delete(id)
46 reject(new Error(`Timed out waiting for main request ${name}.`))
47 }, mainRequestTimeoutMs)
48
49 pendingMainRequests.set(id, {
50 resolve: (value) => resolve(value as RuntimeHostMainResponseMap[TName]),
51 reject,
52 timeout,
53 })
54 })
55
56 process.send({ type: 'main-request', id, name, payload })
57 return await result
58}

Callers 2

createRuntimeFunction · 0.90

Calls 1

resolveFunction · 0.85

Tested by

no test coverage detected