Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

timeoutWith.js 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var async_1 = require("../scheduler/async");
  17. var isDate_1 = require("../util/isDate");
  18. var OuterSubscriber_1 = require("../OuterSubscriber");
  19. var subscribeToResult_1 = require("../util/subscribeToResult");
  20. function timeoutWith(due, withObservable, scheduler) {
  21. if (scheduler === void 0) { scheduler = async_1.async; }
  22. return function (source) {
  23. var absoluteTimeout = isDate_1.isDate(due);
  24. var waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
  25. return source.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler));
  26. };
  27. }
  28. exports.timeoutWith = timeoutWith;
  29. var TimeoutWithOperator = (function () {
  30. function TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler) {
  31. this.waitFor = waitFor;
  32. this.absoluteTimeout = absoluteTimeout;
  33. this.withObservable = withObservable;
  34. this.scheduler = scheduler;
  35. }
  36. TimeoutWithOperator.prototype.call = function (subscriber, source) {
  37. return source.subscribe(new TimeoutWithSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.withObservable, this.scheduler));
  38. };
  39. return TimeoutWithOperator;
  40. }());
  41. var TimeoutWithSubscriber = (function (_super) {
  42. __extends(TimeoutWithSubscriber, _super);
  43. function TimeoutWithSubscriber(destination, absoluteTimeout, waitFor, withObservable, scheduler) {
  44. var _this = _super.call(this, destination) || this;
  45. _this.absoluteTimeout = absoluteTimeout;
  46. _this.waitFor = waitFor;
  47. _this.withObservable = withObservable;
  48. _this.scheduler = scheduler;
  49. _this.action = null;
  50. _this.scheduleTimeout();
  51. return _this;
  52. }
  53. TimeoutWithSubscriber.dispatchTimeout = function (subscriber) {
  54. var withObservable = subscriber.withObservable;
  55. subscriber._unsubscribeAndRecycle();
  56. subscriber.add(subscribeToResult_1.subscribeToResult(subscriber, withObservable));
  57. };
  58. TimeoutWithSubscriber.prototype.scheduleTimeout = function () {
  59. var action = this.action;
  60. if (action) {
  61. this.action = action.schedule(this, this.waitFor);
  62. }
  63. else {
  64. this.add(this.action = this.scheduler.schedule(TimeoutWithSubscriber.dispatchTimeout, this.waitFor, this));
  65. }
  66. };
  67. TimeoutWithSubscriber.prototype._next = function (value) {
  68. if (!this.absoluteTimeout) {
  69. this.scheduleTimeout();
  70. }
  71. _super.prototype._next.call(this, value);
  72. };
  73. TimeoutWithSubscriber.prototype._unsubscribe = function () {
  74. this.action = null;
  75. this.scheduler = null;
  76. this.withObservable = null;
  77. };
  78. return TimeoutWithSubscriber;
  79. }(OuterSubscriber_1.OuterSubscriber));
  80. //# sourceMappingURL=timeoutWith.js.map