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.
1 lines
2.6 KiB
1 lines
2.6 KiB
{"ast":null,"code":"import { SimpleOuterSubscriber, SimpleInnerSubscriber, innerSubscribe } from '../innerSubscribe';\nexport function mergeScan(accumulator, seed, concurrent = Number.POSITIVE_INFINITY) {\n return source => source.lift(new MergeScanOperator(accumulator, seed, concurrent));\n}\nexport class MergeScanOperator {\n constructor(accumulator, seed, concurrent) {\n this.accumulator = accumulator;\n this.seed = seed;\n this.concurrent = concurrent;\n }\n\n call(subscriber, source) {\n return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));\n }\n\n}\nexport class MergeScanSubscriber extends SimpleOuterSubscriber {\n constructor(destination, accumulator, acc, concurrent) {\n super(destination);\n this.accumulator = accumulator;\n this.acc = acc;\n this.concurrent = concurrent;\n this.hasValue = false;\n this.hasCompleted = false;\n this.buffer = [];\n this.active = 0;\n this.index = 0;\n }\n\n _next(value) {\n if (this.active < this.concurrent) {\n const index = this.index++;\n const destination = this.destination;\n let ish;\n\n try {\n const {\n accumulator\n } = this;\n ish = accumulator(this.acc, value, index);\n } catch (e) {\n return destination.error(e);\n }\n\n this.active++;\n\n this._innerSub(ish);\n } else {\n this.buffer.push(value);\n }\n }\n\n _innerSub(ish) {\n const innerSubscriber = new SimpleInnerSubscriber(this);\n const destination = this.destination;\n destination.add(innerSubscriber);\n const innerSubscription = innerSubscribe(ish, innerSubscriber);\n\n if (innerSubscription !== innerSubscriber) {\n destination.add(innerSubscription);\n }\n }\n\n _complete() {\n this.hasCompleted = true;\n\n if (this.active === 0 && this.buffer.length === 0) {\n if (this.hasValue === false) {\n this.destination.next(this.acc);\n }\n\n this.destination.complete();\n }\n\n this.unsubscribe();\n }\n\n notifyNext(innerValue) {\n const {\n destination\n } = this;\n this.acc = innerValue;\n this.hasValue = true;\n destination.next(innerValue);\n }\n\n notifyComplete() {\n const buffer = this.buffer;\n this.active--;\n\n if (buffer.length > 0) {\n this._next(buffer.shift());\n } else if (this.active === 0 && this.hasCompleted) {\n if (this.hasValue === false) {\n this.destination.next(this.acc);\n }\n\n this.destination.complete();\n }\n }\n\n} //# sourceMappingURL=mergeScan.js.map","map":null,"metadata":{},"sourceType":"module"}
|