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.

timer.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. var isScheduler_1 = require("../util/isScheduler");
  7. function timer(dueTime, periodOrScheduler, scheduler) {
  8. if (dueTime === void 0) { dueTime = 0; }
  9. var period = -1;
  10. if (isNumeric_1.isNumeric(periodOrScheduler)) {
  11. period = Number(periodOrScheduler) < 1 && 1 || Number(periodOrScheduler);
  12. }
  13. else if (isScheduler_1.isScheduler(periodOrScheduler)) {
  14. scheduler = periodOrScheduler;
  15. }
  16. if (!isScheduler_1.isScheduler(scheduler)) {
  17. scheduler = async_1.async;
  18. }
  19. return new Observable_1.Observable(function (subscriber) {
  20. var due = isNumeric_1.isNumeric(dueTime)
  21. ? dueTime
  22. : (+dueTime - scheduler.now());
  23. return scheduler.schedule(dispatch, due, {
  24. index: 0, period: period, subscriber: subscriber
  25. });
  26. });
  27. }
  28. exports.timer = timer;
  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