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.

fromIterable.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { Observable } from '../Observable';
  2. import { Subscription } from '../Subscription';
  3. import { iterator as Symbol_iterator } from '../symbol/iterator';
  4. import { subscribeToIterable } from '../util/subscribeToIterable';
  5. export function fromIterable(input, scheduler) {
  6. if (!input) {
  7. throw new Error('Iterable cannot be null');
  8. }
  9. if (!scheduler) {
  10. return new Observable(subscribeToIterable(input));
  11. }
  12. else {
  13. return new Observable(subscriber => {
  14. const sub = new Subscription();
  15. let iterator;
  16. sub.add(() => {
  17. if (iterator && typeof iterator.return === 'function') {
  18. iterator.return();
  19. }
  20. });
  21. sub.add(scheduler.schedule(() => {
  22. iterator = input[Symbol_iterator]();
  23. sub.add(scheduler.schedule(function () {
  24. if (subscriber.closed) {
  25. return;
  26. }
  27. let value;
  28. let done;
  29. try {
  30. const result = iterator.next();
  31. value = result.value;
  32. done = result.done;
  33. }
  34. catch (err) {
  35. subscriber.error(err);
  36. return;
  37. }
  38. if (done) {
  39. subscriber.complete();
  40. }
  41. else {
  42. subscriber.next(value);
  43. this.schedule();
  44. }
  45. }));
  46. }));
  47. return sub;
  48. });
  49. }
  50. }
  51. //# sourceMappingURL=fromIterable.js.map