sdg
Version:
pomelo ts
35 lines (34 loc) • 1.06 kB
TypeScript
/**
* 不带路由参数的远程调用代理
*/
export interface RemoterProxy<F> {
/**
* 使用默认路由参数null调用rpc
*/
defaultRoute: F;
/**
* 路由到serverId服务器,并返回rpc函数
* notify: 只发送消息,不接收返回,节省一次通信。
*/
to(serverId: string, notify?: boolean): F;
/**
* 广播到所有定义了这个remoter的服务器
*/
broadcast: F;
}
/**
* 带路由参数的远程调用代理
*/
export interface RemoterProxyWithRoute<ROUTE, F> extends RemoterProxy<F> {
/**
* 路由到routeParam,并返回rpc调用函数
* notify: 只发送消息,不接收返回,节省一次通信。
*/
route(routeParam: ROUTE, notify?: boolean): F;
(routeParam: ROUTE, ...args: any[]): Promise<any>;
toServer(serverId: string, ...args: any[]): Promise<any>;
toServer(serverId: '*', ...args: any[]): Promise<any[]>;
}
export declare type RemoterClass<ROUTE, T> = {
[P in keyof T]: RemoterProxyWithRoute<ROUTE, T[P]>;
};