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

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