Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

scheduleIterable.js 1.4KB

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