Actualizacion maquina principal
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / _esm2015 / internal / operators / mergeScan.js
1 import { subscribeToResult } from '../util/subscribeToResult';
2 import { OuterSubscriber } from '../OuterSubscriber';
3 import { InnerSubscriber } from '../InnerSubscriber';
4 export function mergeScan(accumulator, seed, concurrent = Number.POSITIVE_INFINITY) {
5     return (source) => source.lift(new MergeScanOperator(accumulator, seed, concurrent));
6 }
7 export class MergeScanOperator {
8     constructor(accumulator, seed, concurrent) {
9         this.accumulator = accumulator;
10         this.seed = seed;
11         this.concurrent = concurrent;
12     }
13     call(subscriber, source) {
14         return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
15     }
16 }
17 export class MergeScanSubscriber extends OuterSubscriber {
18     constructor(destination, accumulator, acc, concurrent) {
19         super(destination);
20         this.accumulator = accumulator;
21         this.acc = acc;
22         this.concurrent = concurrent;
23         this.hasValue = false;
24         this.hasCompleted = false;
25         this.buffer = [];
26         this.active = 0;
27         this.index = 0;
28     }
29     _next(value) {
30         if (this.active < this.concurrent) {
31             const index = this.index++;
32             const destination = this.destination;
33             let ish;
34             try {
35                 const { accumulator } = this;
36                 ish = accumulator(this.acc, value, index);
37             }
38             catch (e) {
39                 return destination.error(e);
40             }
41             this.active++;
42             this._innerSub(ish, value, index);
43         }
44         else {
45             this.buffer.push(value);
46         }
47     }
48     _innerSub(ish, value, index) {
49         const innerSubscriber = new InnerSubscriber(this, value, index);
50         const destination = this.destination;
51         destination.add(innerSubscriber);
52         const innerSubscription = subscribeToResult(this, ish, undefined, undefined, innerSubscriber);
53         if (innerSubscription !== innerSubscriber) {
54             destination.add(innerSubscription);
55         }
56     }
57     _complete() {
58         this.hasCompleted = true;
59         if (this.active === 0 && this.buffer.length === 0) {
60             if (this.hasValue === false) {
61                 this.destination.next(this.acc);
62             }
63             this.destination.complete();
64         }
65         this.unsubscribe();
66     }
67     notifyNext(outerValue, innerValue, outerIndex, innerIndex, innerSub) {
68         const { destination } = this;
69         this.acc = innerValue;
70         this.hasValue = true;
71         destination.next(innerValue);
72     }
73     notifyComplete(innerSub) {
74         const buffer = this.buffer;
75         const destination = this.destination;
76         destination.remove(innerSub);
77         this.active--;
78         if (buffer.length > 0) {
79             this._next(buffer.shift());
80         }
81         else if (this.active === 0 && this.hasCompleted) {
82             if (this.hasValue === false) {
83                 this.destination.next(this.acc);
84             }
85             this.destination.complete();
86         }
87     }
88 }
89 //# sourceMappingURL=mergeScan.js.map