source: trip-planner-front/node_modules/rxjs/internal/operators/delay.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.9 KB
Line 
1"use strict";
2var __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})();
15Object.defineProperty(exports, "__esModule", { value: true });
16var async_1 = require("../scheduler/async");
17var isDate_1 = require("../util/isDate");
18var Subscriber_1 = require("../Subscriber");
19var Notification_1 = require("../Notification");
20function delay(delay, scheduler) {
21 if (scheduler === void 0) { scheduler = async_1.async; }
22 var absoluteDelay = isDate_1.isDate(delay);
23 var delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay);
24 return function (source) { return source.lift(new DelayOperator(delayFor, scheduler)); };
25}
26exports.delay = delay;
27var DelayOperator = (function () {
28 function DelayOperator(delay, scheduler) {
29 this.delay = delay;
30 this.scheduler = scheduler;
31 }
32 DelayOperator.prototype.call = function (subscriber, source) {
33 return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
34 };
35 return DelayOperator;
36}());
37var DelaySubscriber = (function (_super) {
38 __extends(DelaySubscriber, _super);
39 function DelaySubscriber(destination, delay, scheduler) {
40 var _this = _super.call(this, destination) || this;
41 _this.delay = delay;
42 _this.scheduler = scheduler;
43 _this.queue = [];
44 _this.active = false;
45 _this.errored = false;
46 return _this;
47 }
48 DelaySubscriber.dispatch = function (state) {
49 var source = state.source;
50 var queue = source.queue;
51 var scheduler = state.scheduler;
52 var destination = state.destination;
53 while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) {
54 queue.shift().notification.observe(destination);
55 }
56 if (queue.length > 0) {
57 var delay_1 = Math.max(0, queue[0].time - scheduler.now());
58 this.schedule(state, delay_1);
59 }
60 else {
61 this.unsubscribe();
62 source.active = false;
63 }
64 };
65 DelaySubscriber.prototype._schedule = function (scheduler) {
66 this.active = true;
67 var destination = this.destination;
68 destination.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
69 source: this, destination: this.destination, scheduler: scheduler
70 }));
71 };
72 DelaySubscriber.prototype.scheduleNotification = function (notification) {
73 if (this.errored === true) {
74 return;
75 }
76 var scheduler = this.scheduler;
77 var message = new DelayMessage(scheduler.now() + this.delay, notification);
78 this.queue.push(message);
79 if (this.active === false) {
80 this._schedule(scheduler);
81 }
82 };
83 DelaySubscriber.prototype._next = function (value) {
84 this.scheduleNotification(Notification_1.Notification.createNext(value));
85 };
86 DelaySubscriber.prototype._error = function (err) {
87 this.errored = true;
88 this.queue = [];
89 this.destination.error(err);
90 this.unsubscribe();
91 };
92 DelaySubscriber.prototype._complete = function () {
93 this.scheduleNotification(Notification_1.Notification.createComplete());
94 this.unsubscribe();
95 };
96 return DelaySubscriber;
97}(Subscriber_1.Subscriber));
98var DelayMessage = (function () {
99 function DelayMessage(time, notification) {
100 this.time = time;
101 this.notification = notification;
102 }
103 return DelayMessage;
104}());
105//# sourceMappingURL=delay.js.map
Note: See TracBrowser for help on using the repository browser.