UNPKG

1.09 kBTypeScriptView Raw
1import FunctionHandleRegistry from './function-handle-registry';
2import { MessageEndpoint } from '.';
3/**
4 * Coordinates command/response pairs across a given `MessageEndpoint`, returning
5 * a promise for each outgoing command and dispatching incoming ones to a given
6 * executor.
7 */
8export default class CommandCoordinator<Commands> {
9 private endpoint;
10 private handleRegistry;
11 private executor;
12 private nextSeq;
13 private pendingCommands;
14 constructor(endpoint: MessageEndpoint, handleRegistry: FunctionHandleRegistry, executor: Commands);
15 sendCommand<Name extends keyof Commands>(name: Name, ...args: CommandParams<Commands[Name]>): Promise<CommandReturn<Commands[Name]>>;
16 private messageReceived;
17 private dispatchResponse;
18 private dispatchCommand;
19 private sendMessage;
20 private pendingDeferred;
21 private isResponse;
22 private isCommand;
23}
24declare type CommandParams<T> = T extends (...params: infer Params) => any ? Params : never;
25declare type CommandReturn<T> = T extends (...params: any[]) => infer Return ? Return : never;
26export {};