( host: HostConnection, name: TName, payload: RuntimeHostRequestMap[TName], )
| 527 | } |
| 528 | |
| 529 | async 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 | |
| 553 | export function subscribeRuntimeHostEvents(listener: (event: DesktopEvent) => void) { |
| 554 | desktopListeners.add(listener) |
no test coverage detected