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.

range.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { Observable } from '../Observable';
  2. export function range(start = 0, count, scheduler) {
  3. return new Observable(subscriber => {
  4. if (count === undefined) {
  5. count = start;
  6. start = 0;
  7. }
  8. let index = 0;
  9. let current = start;
  10. if (scheduler) {
  11. return scheduler.schedule(dispatch, 0, {
  12. index, count, start, subscriber
  13. });
  14. }
  15. else {
  16. do {
  17. if (index++ >= count) {
  18. subscriber.complete();
  19. break;
  20. }
  21. subscriber.next(current++);
  22. if (subscriber.closed) {
  23. break;
  24. }
  25. } while (true);
  26. }
  27. return undefined;
  28. });
  29. }
  30. export function dispatch(state) {
  31. const { start, index, count, subscriber } = state;
  32. if (index >= count) {
  33. subscriber.complete();
  34. return;
  35. }
  36. subscriber.next(start);
  37. if (subscriber.closed) {
  38. return;
  39. }
  40. state.index = index + 1;
  41. state.start = start + 1;
  42. this.schedule(state);
  43. }
  44. //# sourceMappingURL=range.js.map