1 | /** PURE_IMPORTS_START _Observable,_scheduler_async,_util_isNumeric,_util_isScheduler PURE_IMPORTS_END */
|
---|
2 | import { Observable } from '../Observable';
|
---|
3 | import { async } from '../scheduler/async';
|
---|
4 | import { isNumeric } from '../util/isNumeric';
|
---|
5 | import { isScheduler } from '../util/isScheduler';
|
---|
6 | export function timer(dueTime, periodOrScheduler, scheduler) {
|
---|
7 | if (dueTime === void 0) {
|
---|
8 | dueTime = 0;
|
---|
9 | }
|
---|
10 | var period = -1;
|
---|
11 | if (isNumeric(periodOrScheduler)) {
|
---|
12 | period = Number(periodOrScheduler) < 1 && 1 || Number(periodOrScheduler);
|
---|
13 | }
|
---|
14 | else if (isScheduler(periodOrScheduler)) {
|
---|
15 | scheduler = periodOrScheduler;
|
---|
16 | }
|
---|
17 | if (!isScheduler(scheduler)) {
|
---|
18 | scheduler = async;
|
---|
19 | }
|
---|
20 | return new Observable(function (subscriber) {
|
---|
21 | var due = isNumeric(dueTime)
|
---|
22 | ? dueTime
|
---|
23 | : (+dueTime - scheduler.now());
|
---|
24 | return scheduler.schedule(dispatch, due, {
|
---|
25 | index: 0, period: period, subscriber: subscriber
|
---|
26 | });
|
---|
27 | });
|
---|
28 | }
|
---|
29 | function dispatch(state) {
|
---|
30 | var index = state.index, period = state.period, subscriber = state.subscriber;
|
---|
31 | subscriber.next(index);
|
---|
32 | if (subscriber.closed) {
|
---|
33 | return;
|
---|
34 | }
|
---|
35 | else if (period === -1) {
|
---|
36 | return subscriber.complete();
|
---|
37 | }
|
---|
38 | state.index = index + 1;
|
---|
39 | this.schedule(state, period);
|
---|
40 | }
|
---|
41 | //# sourceMappingURL=timer.js.map
|
---|