exhaustMap.js 1.1 KB

123456789101112131415161718192021222324252627
  1. import { map } from './map';
  2. import { innerFrom } from '../observable/innerFrom';
  3. import { operate } from '../util/lift';
  4. import { createOperatorSubscriber } from './OperatorSubscriber';
  5. export function exhaustMap(project, resultSelector) {
  6. if (resultSelector) {
  7. return (source) => source.pipe(exhaustMap((a, i) => innerFrom(project(a, i)).pipe(map((b, ii) => resultSelector(a, b, i, ii)))));
  8. }
  9. return operate((source, subscriber) => {
  10. let index = 0;
  11. let innerSub = null;
  12. let isComplete = false;
  13. source.subscribe(createOperatorSubscriber(subscriber, (outerValue) => {
  14. if (!innerSub) {
  15. innerSub = createOperatorSubscriber(subscriber, undefined, () => {
  16. innerSub = null;
  17. isComplete && subscriber.complete();
  18. });
  19. innerFrom(project(outerValue, index++)).subscribe(innerSub);
  20. }
  21. }, () => {
  22. isComplete = true;
  23. !innerSub && subscriber.complete();
  24. }));
  25. });
  26. }
  27. //# sourceMappingURL=exhaustMap.js.map