mergeInternals.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.mergeInternals = void 0;
  4. var innerFrom_1 = require("../observable/innerFrom");
  5. var executeSchedule_1 = require("../util/executeSchedule");
  6. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  7. function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
  8. var buffer = [];
  9. var active = 0;
  10. var index = 0;
  11. var isComplete = false;
  12. var checkComplete = function () {
  13. if (isComplete && !buffer.length && !active) {
  14. subscriber.complete();
  15. }
  16. };
  17. var outerNext = function (value) { return (active < concurrent ? doInnerSub(value) : buffer.push(value)); };
  18. var doInnerSub = function (value) {
  19. expand && subscriber.next(value);
  20. active++;
  21. var innerComplete = false;
  22. innerFrom_1.innerFrom(project(value, index++)).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (innerValue) {
  23. onBeforeNext === null || onBeforeNext === void 0 ? void 0 : onBeforeNext(innerValue);
  24. if (expand) {
  25. outerNext(innerValue);
  26. }
  27. else {
  28. subscriber.next(innerValue);
  29. }
  30. }, function () {
  31. innerComplete = true;
  32. }, undefined, function () {
  33. if (innerComplete) {
  34. try {
  35. active--;
  36. var _loop_1 = function () {
  37. var bufferedValue = buffer.shift();
  38. if (innerSubScheduler) {
  39. executeSchedule_1.executeSchedule(subscriber, innerSubScheduler, function () { return doInnerSub(bufferedValue); });
  40. }
  41. else {
  42. doInnerSub(bufferedValue);
  43. }
  44. };
  45. while (buffer.length && active < concurrent) {
  46. _loop_1();
  47. }
  48. checkComplete();
  49. }
  50. catch (err) {
  51. subscriber.error(err);
  52. }
  53. }
  54. }));
  55. };
  56. source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, outerNext, function () {
  57. isComplete = true;
  58. checkComplete();
  59. }));
  60. return function () {
  61. additionalFinalizer === null || additionalFinalizer === void 0 ? void 0 : additionalFinalizer();
  62. };
  63. }
  64. exports.mergeInternals = mergeInternals;
  65. //# sourceMappingURL=mergeInternals.js.map