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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var Observable_1 = require("../Observable");
  4. var Subscription_1 = require("../Subscription");
  5. var iterator_1 = require("../symbol/iterator");
  6. var subscribeToIterable_1 = require("../util/subscribeToIterable");
  7. function fromIterable(input, scheduler) {
  8. if (!input) {
  9. throw new Error('Iterable cannot be null');
  10. }
  11. if (!scheduler) {
  12. return new Observable_1.Observable(subscribeToIterable_1.subscribeToIterable(input));
  13. }
  14. else {
  15. return new Observable_1.Observable(function (subscriber) {
  16. var sub = new Subscription_1.Subscription();
  17. var iterator;
  18. sub.add(function () {
  19. if (iterator && typeof iterator.return === 'function') {
  20. iterator.return();
  21. }
  22. });
  23. sub.add(scheduler.schedule(function () {
  24. iterator = input[iterator_1.iterator]();
  25. sub.add(scheduler.schedule(function () {
  26. if (subscriber.closed) {
  27. return;
  28. }
  29. var value;
  30. var done;
  31. try {
  32. var result = iterator.next();
  33. value = result.value;
  34. done = result.done;
  35. }
  36. catch (err) {
  37. subscriber.error(err);
  38. return;
  39. }
  40. if (done) {
  41. subscriber.complete();
  42. }
  43. else {
  44. subscriber.next(value);
  45. this.schedule();
  46. }
  47. }));
  48. }));
  49. return sub;
  50. });
  51. }
  52. }
  53. exports.fromIterable = fromIterable;
  54. //# sourceMappingURL=fromIterable.js.map