interval.js 1.0 KB

1234567891011121314151617181920212223242526
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var Observable_1 = require("../Observable");
  4. var async_1 = require("../scheduler/async");
  5. var isNumeric_1 = require("../util/isNumeric");
  6. function interval(period, scheduler) {
  7. if (period === void 0) { period = 0; }
  8. if (scheduler === void 0) { scheduler = async_1.async; }
  9. if (!isNumeric_1.isNumeric(period) || period < 0) {
  10. period = 0;
  11. }
  12. if (!scheduler || typeof scheduler.schedule !== 'function') {
  13. scheduler = async_1.async;
  14. }
  15. return new Observable_1.Observable(function (subscriber) {
  16. subscriber.add(scheduler.schedule(dispatch, period, { subscriber: subscriber, counter: 0, period: period }));
  17. return subscriber;
  18. });
  19. }
  20. exports.interval = interval;
  21. function dispatch(state) {
  22. var subscriber = state.subscriber, counter = state.counter, period = state.period;
  23. subscriber.next(counter);
  24. this.schedule({ subscriber: subscriber, counter: counter + 1, period: period }, period);
  25. }
  26. //# sourceMappingURL=interval.js.map