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.1KB

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