Stream.d.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /** Defines the expected type for a receiver of results streamed by the server.
  2. *
  3. * @typeparam T The type of the items being sent by the server.
  4. */
  5. export interface IStreamSubscriber<T> {
  6. /** A boolean that will be set by the {@link @microsoft/signalr.IStreamResult} when the stream is closed. */
  7. closed?: boolean;
  8. /** Called by the framework when a new item is available. */
  9. next(value: T): void;
  10. /** Called by the framework when an error has occurred.
  11. *
  12. * After this method is called, no additional methods on the {@link @microsoft/signalr.IStreamSubscriber} will be called.
  13. */
  14. error(err: any): void;
  15. /** Called by the framework when the end of the stream is reached.
  16. *
  17. * After this method is called, no additional methods on the {@link @microsoft/signalr.IStreamSubscriber} will be called.
  18. */
  19. complete(): void;
  20. }
  21. /** Defines the result of a streaming hub method.
  22. *
  23. * @typeparam T The type of the items being sent by the server.
  24. */
  25. export interface IStreamResult<T> {
  26. /** Attaches a {@link @microsoft/signalr.IStreamSubscriber}, which will be invoked when new items are available from the stream.
  27. *
  28. * @param {IStreamSubscriber<T>} observer The subscriber to attach.
  29. * @returns {ISubscription<T>} A subscription that can be disposed to terminate the stream and stop calling methods on the {@link @microsoft/signalr.IStreamSubscriber}.
  30. */
  31. subscribe(subscriber: IStreamSubscriber<T>): ISubscription<T>;
  32. }
  33. /** An interface that allows an {@link @microsoft/signalr.IStreamSubscriber} to be disconnected from a stream.
  34. *
  35. * @typeparam T The type of the items being sent by the server.
  36. */
  37. export interface ISubscription<T> {
  38. /** Disconnects the {@link @microsoft/signalr.IStreamSubscriber} associated with this subscription from the stream. */
  39. dispose(): void;
  40. }