Front end of the Slack clone application.

timeoutWith.js 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /** PURE_IMPORTS_START .._scheduler_async,.._operators_timeoutWith PURE_IMPORTS_END */
  2. import { async } from '../scheduler/async';
  3. import { timeoutWith as higherOrder } from '../operators/timeoutWith';
  4. /* tslint:enable:max-line-length */
  5. /**
  6. *
  7. * Errors if Observable does not emit a value in given time span, in case of which
  8. * subscribes to the second Observable.
  9. *
  10. * <span class="informal">It's a version of `timeout` operator that let's you specify fallback Observable.</span>
  11. *
  12. * <img src="./img/timeoutWith.png" width="100%">
  13. *
  14. * `timeoutWith` is a variation of `timeout` operator. It behaves exactly the same,
  15. * still accepting as a first argument either a number or a Date, which control - respectively -
  16. * when values of source Observable should be emitted or when it should complete.
  17. *
  18. * The only difference is that it accepts a second, required parameter. This parameter
  19. * should be an Observable which will be subscribed when source Observable fails any timeout check.
  20. * So whenever regular `timeout` would emit an error, `timeoutWith` will instead start re-emitting
  21. * values from second Observable. Note that this fallback Observable is not checked for timeouts
  22. * itself, so it can emit values and complete at arbitrary points in time. From the moment of a second
  23. * subscription, Observable returned from `timeoutWith` simply mirrors fallback stream. When that
  24. * stream completes, it completes as well.
  25. *
  26. * Scheduler, which in case of `timeout` is provided as as second argument, can be still provided
  27. * here - as a third, optional parameter. It still is used to schedule timeout checks and -
  28. * as a consequence - when second Observable will be subscribed, since subscription happens
  29. * immediately after failing check.
  30. *
  31. * @example <caption>Add fallback observable</caption>
  32. * const seconds = Rx.Observable.interval(1000);
  33. * const minutes = Rx.Observable.interval(60 * 1000);
  34. *
  35. * seconds.timeoutWith(900, minutes)
  36. * .subscribe(
  37. * value => console.log(value), // After 900ms, will start emitting `minutes`,
  38. * // since first value of `seconds` will not arrive fast enough.
  39. * err => console.log(err) // Would be called after 900ms in case of `timeout`,
  40. * // but here will never be called.
  41. * );
  42. *
  43. * @param {number|Date} due Number specifying period within which Observable must emit values
  44. * or Date specifying before when Observable should complete
  45. * @param {Observable<T>} withObservable Observable which will be subscribed if source fails timeout check.
  46. * @param {Scheduler} [scheduler] Scheduler controlling when timeout checks occur.
  47. * @return {Observable<T>} Observable that mirrors behaviour of source or, when timeout check fails, of an Observable
  48. * passed as a second parameter.
  49. * @method timeoutWith
  50. * @owner Observable
  51. */
  52. export function timeoutWith(due, withObservable, scheduler) {
  53. if (scheduler === void 0) {
  54. scheduler = async;
  55. }
  56. return higherOrder(due, withObservable, scheduler)(this);
  57. }
  58. //# sourceMappingURL=timeoutWith.js.map