UNPKG

2.25 kBTypeScriptView Raw
1import { Operator, Stream, MemoryStream } from '../index';
2export declare class FlattenConcAMOperator<T> implements Operator<Stream<T>, T> {
3 n: number;
4 ins: Stream<Stream<T>>;
5 type: string;
6 out: Stream<T>;
7 private _l;
8 private _d;
9 private _seq;
10 constructor(n: number, ins: Stream<Stream<T>>);
11 _start(out: Stream<T>): void;
12 _stop(): void;
13 less(): void;
14 _n(s: Stream<T>): void;
15 _e(err: any): void;
16 _c(): void;
17}
18/**
19 * Flattens a "stream of streams", handling multiple concurrent nested streams
20 * simultaneously, up to some limit `n`.
21 *
22 * If the input stream is a stream that emits streams, then this operator will
23 * return an output stream which is a flat stream: emits regular events. The
24 * flattening happens concurrently, up to the configured limit. It works like
25 * this: when the input stream emits a nested stream,
26 * *flattenConcurrentlyAtMost* will start imitating that nested one. When the
27 * next nested stream is emitted on the input stream,
28 * *flattenConcurrentlyAtMost* will check to see how many streams it is connected
29 * to. If it is connected to a number of streams less than the limit, it will also
30 * imitate that new one, but will continue to imitate the previous nested streams
31 * as well.
32 *
33 * If the limit has already been reached, *flattenConcurrentlyAtMost* will put the
34 * stream in a queue. When any of the streams it is listening to completes, a stream
35 * is taken out of the queue and `flattenConcurrentlyAtMost` will connect to it.
36 *
37 * This process continues until the metastream completes and there are no more
38 * connected streams or streams in the queue.
39 *
40 * Marble diagrams:
41 *
42 * ```text
43 * --+--------+---------------
44 * \ \
45 * \ ----1----2---3--|
46 * --a--b----c----|
47 * flattenConcurrentlyAtMost(1)
48 * -----a--b----c-1----2---3--|
49 * ```
50 *
51 * ```text
52 * --+---+---+-|
53 * \ \ \
54 * \ \ ---fgh----i-----jh--|
55 * \ -----1----2----3--|
56 * ---a--b-----c--|
57 * flattenConcurrentlyAtMost(2)
58 * ---------a--b-1---c2--i-3------fgh----i-----jh--|
59 * ```
60 *
61 * @return {Stream}
62 */
63export default function flattenConcurrentlyAtMost<T>(n: number): (ins: Stream<Stream<T> | MemoryStream<T>>) => Stream<T>;