a zip code crypto-currency system good for red ONLY

timeoutWith.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. var async_1 = require('../scheduler/async');
  3. var timeoutWith_1 = require('../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. function timeoutWith(due, withObservable, scheduler) {
  53. if (scheduler === void 0) { scheduler = async_1.async; }
  54. return timeoutWith_1.timeoutWith(due, withObservable, scheduler)(this);
  55. }
  56. exports.timeoutWith = timeoutWith;
  57. //# sourceMappingURL=timeoutWith.js.map