Type runtime event fanout by websocket channel contracts
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
fcd4bd5a77
commit
c93cf95cbe
1 file changed
+7
-1
@@ -13,6 +13,7 @@ import {
|
||||
type ProviderSession,
|
||||
type WsClientMessage,
|
||||
type WsResponseMessage,
|
||||
type WsServerMessage,
|
||||
WS_EVENT_CHANNELS,
|
||||
WS_CLOSE_CODES,
|
||||
WS_CLOSE_REASONS,
|
||||
@@ -68,6 +69,8 @@ interface BootstrapSessionResult {
|
||||
bootstrapError: string | undefined;
|
||||
}
|
||||
|
||||
type WsServerEventMessage = Extract<WsServerMessage, { type: "event" }>;
|
||||
|
||||
function raceWithTimeout<T>(
|
||||
promise: Promise<T>,
|
||||
timeoutMs: number,
|
||||
@@ -368,7 +371,10 @@ export async function startRuntimeApiServer(
|
||||
let launchSessionPromise: Promise<BootstrapSessionResult> | null = null;
|
||||
let bootstrapFallbackSession: ProviderSession | null = null;
|
||||
|
||||
const emitEvent = (channel: string, payload: unknown) => {
|
||||
const emitEvent = <TChannel extends WsServerEventMessage["channel"]>(
|
||||
channel: TChannel,
|
||||
payload: Extract<WsServerEventMessage, { channel: TChannel }>["payload"],
|
||||
) => {
|
||||
if (!activeClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user