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

Function invokeRuntimeHostOnHost

desktop/runtime-host/client-bridge.ts:529–551  ·  view source on GitHub ↗
(
  host: HostConnection,
  name: TName,
  payload: RuntimeHostRequestMap[TName],
)

Source from the content-addressed store, hash-verified

527}
528
529async function invokeRuntimeHostOnHost<TName extends RuntimeHostRequestName>(
530 host: HostConnection,
531 name: TName,
532 payload: RuntimeHostRequestMap[TName],
533): Promise<RuntimeHostResponseMap[TName]> {
534 const child = await ensureRuntimeHost(host)
535 const id = randomUUID()
536
537 return await new Promise<RuntimeHostResponseMap[TName]>((resolve, reject) => {
538 host.pendingRequests.set(id, {
539 name,
540 resolve: (value) => resolve(value as RuntimeHostResponseMap[TName]),
541 reject,
542 })
543
544 child.send({ type: 'request', id, name, payload }, (error) => {
545 if (!error) return
546 host.pendingRequests.delete(id)
547 scheduleThreadHostIdleStop(host)
548 reject(error)
549 })
550 })
551}
552
553export function subscribeRuntimeHostEvents(listener: (event: DesktopEvent) => void) {
554 desktopListeners.add(listener)

Callers 1

Calls 3

ensureRuntimeHostFunction · 0.85
resolveFunction · 0.85

Tested by

no test coverage detected