RpcProvider.d.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Event } from 'microevent.ts';
  2. import RpcProviderInterface from './RpcProviderInterface';
  3. declare class RpcProvider implements RpcProviderInterface {
  4. private _dispatch;
  5. private _rpcTimeout;
  6. constructor(_dispatch: RpcProvider.Dispatcher, _rpcTimeout?: number);
  7. dispatch(payload: any): void;
  8. rpc<T, U>(id: string, payload?: T, transfer?: any): Promise<U>;
  9. signal<T>(id: string, payload?: T, transfer?: any): this;
  10. registerRpcHandler<T, U>(id: string, handler: RpcProviderInterface.RpcHandler<T, U>): this;
  11. registerSignalHandler<T>(id: string, handler: RpcProviderInterface.SignalHandler<T>): this;
  12. deregisterRpcHandler<T, U>(id: string, handler: RpcProviderInterface.RpcHandler<T, U>): this;
  13. deregisterSignalHandler<T>(id: string, handler: RpcProviderInterface.SignalHandler<T>): this;
  14. private _raiseError;
  15. private _handleSignal;
  16. private _handeRpc;
  17. private _handleInternal;
  18. private _transactionTimeout;
  19. private _clearTransaction;
  20. error: Event<Error>;
  21. private _rpcHandlers;
  22. private _signalHandlers;
  23. private _pendingTransactions;
  24. private _nextTransactionId;
  25. }
  26. declare module RpcProvider {
  27. enum MessageType {
  28. signal = 0,
  29. rpc = 1,
  30. internal = 2
  31. }
  32. interface Dispatcher {
  33. (message: Message, transfer?: Array<any>): void;
  34. }
  35. interface Message {
  36. type: MessageType;
  37. transactionId?: number;
  38. id: string;
  39. payload?: any;
  40. }
  41. }
  42. export default RpcProvider;