Front end of the Slack clone application.

timeout.js 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /** PURE_IMPORTS_START .._scheduler_async,.._operators_timeout PURE_IMPORTS_END */
  2. import { async } from '../scheduler/async';
  3. import { timeout as higherOrder } from '../operators/timeout';
  4. /**
  5. *
  6. * Errors if Observable does not emit a value in given time span.
  7. *
  8. * <span class="informal">Timeouts on Observable that doesn't emit values fast enough.</span>
  9. *
  10. * <img src="./img/timeout.png" width="100%">
  11. *
  12. * `timeout` operator accepts as an argument either a number or a Date.
  13. *
  14. * If number was provided, it returns an Observable that behaves like a source
  15. * Observable, unless there is a period of time where there is no value emitted.
  16. * So if you provide `100` as argument and first value comes after 50ms from
  17. * the moment of subscription, this value will be simply re-emitted by the resulting
  18. * Observable. If however after that 100ms passes without a second value being emitted,
  19. * stream will end with an error and source Observable will be unsubscribed.
  20. * These checks are performed throughout whole lifecycle of Observable - from the moment
  21. * it was subscribed to, until it completes or errors itself. Thus every value must be
  22. * emitted within specified period since previous value.
  23. *
  24. * If provided argument was Date, returned Observable behaves differently. It throws
  25. * if Observable did not complete before provided Date. This means that periods between
  26. * emission of particular values do not matter in this case. If Observable did not complete
  27. * before provided Date, source Observable will be unsubscribed. Other than that, resulting
  28. * stream behaves just as source Observable.
  29. *
  30. * `timeout` accepts also a Scheduler as a second parameter. It is used to schedule moment (or moments)
  31. * when returned Observable will check if source stream emitted value or completed.
  32. *
  33. * @example <caption>Check if ticks are emitted within certain timespan</caption>
  34. * const seconds = Rx.Observable.interval(1000);
  35. *
  36. * seconds.timeout(1100) // Let's use bigger timespan to be safe,
  37. * // since `interval` might fire a bit later then scheduled.
  38. * .subscribe(
  39. * value => console.log(value), // Will emit numbers just as regular `interval` would.
  40. * err => console.log(err) // Will never be called.
  41. * );
  42. *
  43. * seconds.timeout(900).subscribe(
  44. * value => console.log(value), // Will never be called.
  45. * err => console.log(err) // Will emit error before even first value is emitted,
  46. * // since it did not arrive within 900ms period.
  47. * );
  48. *
  49. * @example <caption>Use Date to check if Observable completed</caption>
  50. * const seconds = Rx.Observable.interval(1000);
  51. *
  52. * seconds.timeout(new Date("December 17, 2020 03:24:00"))
  53. * .subscribe(
  54. * value => console.log(value), // Will emit values as regular `interval` would
  55. * // until December 17, 2020 at 03:24:00.
  56. * err => console.log(err) // On December 17, 2020 at 03:24:00 it will emit an error,
  57. * // since Observable did not complete by then.
  58. * );
  59. *
  60. * @see {@link timeoutWith}
  61. *
  62. * @param {number|Date} due Number specifying period within which Observable must emit values
  63. * or Date specifying before when Observable should complete
  64. * @param {Scheduler} [scheduler] Scheduler controlling when timeout checks occur.
  65. * @return {Observable<T>} Observable that mirrors behaviour of source, unless timeout checks fail.
  66. * @method timeout
  67. * @owner Observable
  68. */
  69. export function timeout(due, scheduler) {
  70. if (scheduler === void 0) {
  71. scheduler = async;
  72. }
  73. return higherOrder(due, scheduler)(this);
  74. }
  75. //# sourceMappingURL=timeout.js.map