1+ //#region src/index.d.ts
12declare class Queue < T > {
2- static EOF : undefined ;
3- private _queue ;
4- private _prom ;
5- private _resolveNext ;
6- private _endProm ;
7- private _resolveEnd ;
8- private _pushCount ;
9- private _shiftResolvers ;
10- ended : boolean ;
11- piped : boolean ;
12- private static readonly _batchCount ;
13- private static readonly _eof ;
14- constructor ( ) ;
15- private _run ;
16- private _waitForPush ;
17- private _shift ;
18- /**
19- * Creates a new queue from an array of values.
20- * @param array The array to create the queue from.
21- * @returns A new queue containing the values from the array.
22- */
23- static fromArray < T > ( array : Array < T > ) : Queue < T > ;
24- private _preparePipe ;
25- waitForShift : ( ) => Promise < void > ;
26- /**
27- * Returns a promise that resolves when the queue has ended.
28- */
29- waitForEnd : ( ) => Promise < void > ;
30- /**
31- * Returns the current size of the queue.
32- */
33- size : ( ) => number ;
34- /**
35- * Returns the total number of values pushed into the queue.
36- */
37- pushCount : ( ) => number ;
38- /**
39- * Pushes one or more values into the queue.
40- * @param vals The values to push into the queue.
41- */
42- push : ( ...vals : T [ ] ) => void ;
43- /**
44- * Ends the queue, indicating that no more values will be pushed.
45- */
46- end : ( ) => void ;
47- /**
48- * Shifts a value from the queue without any safety checks.
49- */
50- shiftUnsafe : ( ) => Promise < T | undefined > ;
51- /**
52- * Implements the async iterator protocol, allowing the queue to be consumed
53- * in a for-await-of loop. Marks the queue as piped.
54- * @example
55- * for await (const item of queue) {
56- * console.log(item);
57- * }
58- * @returns An async generator that yields values from the queue.
59- */
60- [ Symbol . asyncIterator ] : ( this : Queue < T > ) => AsyncGenerator < T , void , unknown > ;
61- /**
62- * Maps each value in the queue using the provided callback function.
63- * @param callback The function to apply to each value in the queue.
64- */
65- map : ( callback : ( v : T ) => void ) => Promise < void > ;
66- /**
67- * Maps each value in the queue using the provided async callback function in parallel.
68- * @param callback The async function to apply to each value in the queue.
69- * @param n The maximum number of parallel executions (default: Queue._batchCount).
70- */
71- mapParallel : ( callback : ( v : T ) => Promise < unknown > , n ?: number ) => Promise < void > ;
72- /**
73- * Pipes the values from the queue through the provided callback function and returns a new queue with the results.
74- * @param callback The function to apply to each value in the queue.
75- * @returns A new queue containing the results of the callback function.
76- */
77- pipe : < U > ( callback : ( v : T ) => U | undefined ) => Queue < U > ;
78- /**
79- * Pipes the values from the queue through the provided async callback function and returns a new queue with the results.
80- * @param callback The async function to apply to each value in the queue.
81- * @param n The maximum number of parallel executions (default: Queue._batchCount).
82- * @returns A new queue containing the results of the async callback function.
83- */
84- upipe : < U > ( callback : ( v : T ) => Promise < U | undefined > , n ?: number ) => Queue < U > ;
85- /**
86- * Splits the queue into two new queues based on the provided callback function.
87- * @param callback The function to determine which queue each value should be sent to.
88- * @returns A tuple containing the two new queues.
89- */
90- split : < U , V = U > ( callback : ( v : T ) => [ U , 0 ] | [ V , 1 ] ) => [ Queue < U > , Queue < V > ] ;
91- /**
92- * Batches the values in the queue into arrays of the specified size.
93- * @param n The size of each batch.
94- * @returns A new queue containing arrays of values from the original queue.
95- */
96- batch : ( n : number ) => Queue < T [ ] > ;
97- /**
98- * Flattens the values in the queue, assuming each value is an array.
99- * @returns A new queue containing the flattened values.
100- */
101- flat : ( ) => Queue < T extends ( infer U ) [ ] ? U : never > ;
102- /**
103- * Splits the queue into two new queues based on the provided async callback function.
104- * @param callback The async function to determine which queue each value should be sent to.
105- * @param n The maximum number of parallel executions (default: Queue._batchCount).
106- * @returns A tuple containing the two new queues.
107- */
108- usplit : < U , V = U > ( callback : ( v : T ) => Promise < [ U , 0 ] | [ V , 1 ] | undefined > , n ?: number ) => [ Queue < U > , Queue < V > ] ;
109- /**
110- * Merges the values from another queue into this queue.
111- * @param q The queue to merge values from.
112- * @returns A new queue containing the merged values.
113- */
114- umerge : ( q : Queue < T > ) => Queue < T > ;
115- /**
116- * Creates multiple clones of the queue.
117- * @param count The number of clone queues to create (default: 1).
118- * @returns An array of cloned queues.
119- */
120- clone : ( count ?: number ) => Queue < T > [ ] ;
121- /**
122- * Collects all the values in the queue into an array.
123- * @returns A promise that resolves to an array containing all the values in the queue.
124- */
125- collect : ( ) => Promise < T [ ] > ;
3+ #private;
4+ static EOF : undefined ;
5+ ended : boolean ;
6+ piped : boolean ;
7+ constructor ( ) ;
8+ /**
9+ * Creates a new queue from an array of values.
10+ * @param array The array to create the queue from.
11+ * @returns A new queue containing the values from the array.
12+ */
13+ static fromArray < T > ( array : Array < T > ) : Queue < T > ;
14+ waitForShift : ( ) => Promise < void > ;
15+ /**
16+ * Returns a promise that resolves when the queue has ended.
17+ */
18+ waitForEnd : ( ) => Promise < void > ;
19+ /**
20+ * Returns the current size of the queue.
21+ */
22+ size : ( ) => number ;
23+ /**
24+ * Returns the total number of values pushed into the queue.
25+ */
26+ pushCount : ( ) => number ;
27+ /**
28+ * Pushes one or more values into the queue.
29+ * @param vals The values to push into the queue.
30+ */
31+ push : ( ...vals : T [ ] ) => void ;
32+ /**
33+ * Ends the queue, indicating that no more values will be pushed.
34+ */
35+ end : ( ) => void ;
36+ /**
37+ * Shifts a value from the queue without any safety checks.
38+ */
39+ shiftUnsafe : ( ) => Promise < T | undefined > ;
40+ /**
41+ * Implements the async iterator protocol, allowing the queue to be consumed
42+ * in a for-await-of loop. Marks the queue as piped.
43+ * @example
44+ * for await (const item of queue) {
45+ * console.log(item);
46+ * }
47+ * @returns An async generator that yields values from the queue.
48+ */
49+ [ Symbol . asyncIterator ] : ( this : Queue < T > ) => AsyncGenerator < T , void , unknown > ;
50+ /**
51+ * Maps each value in the queue using the provided callback function.
52+ * @param callback The function to apply to each value in the queue.
53+ */
54+ map : ( callback : ( v : T ) => void ) => Promise < void > ;
55+ /**
56+ * Maps each value in the queue using the provided async callback function in parallel.
57+ * @param callback The async function to apply to each value in the queue.
58+ * @param n The maximum number of parallel executions (default: Queue.#batchCount).
59+ */
60+ mapParallel : ( callback : ( v : T ) => Promise < unknown > , n ?: number ) => Promise < void > ;
61+ /**
62+ * Pipes the values from the queue through the provided callback function and returns a new queue with the results.
63+ * @param callback The function to apply to each value in the queue.
64+ * @returns A new queue containing the results of the callback function.
65+ */
66+ pipe : < U > ( callback : ( v : T ) => U | undefined ) => Queue < U > ;
67+ /**
68+ * Pipes the values from the queue through the provided async callback function and returns a new queue with the results.
69+ * @param callback The async function to apply to each value in the queue.
70+ * @param n The maximum number of parallel executions (default: Queue.#batchCount).
71+ * @returns A new queue containing the results of the async callback function.
72+ */
73+ upipe : < U > ( callback : ( v : T ) => Promise < U | undefined > , n ?: number ) => Queue < U > ;
74+ /**
75+ * Splits the queue into two new queues based on the provided callback function.
76+ * @param callback The function to determine which queue each value should be sent to.
77+ * @returns A tuple containing the two new queues.
78+ */
79+ split : < U , V = U > ( callback : ( v : T ) => [ U , 0 ] | [ V , 1 ] ) => [ Queue < U > , Queue < V > ] ;
80+ /**
81+ * Batches the values in the queue into arrays of the specified size.
82+ * @param n The size of each batch.
83+ * @returns A new queue containing arrays of values from the original queue.
84+ */
85+ batch : ( n : number ) => Queue < T [ ] > ;
86+ /**
87+ * Flattens the values in the queue, assuming each value is an array.
88+ * @returns A new queue containing the flattened values.
89+ */
90+ flat : ( ) => Queue < T extends ( infer U ) [ ] ? U : never > ;
91+ /**
92+ * Splits the queue into two new queues based on the provided async callback function.
93+ * @param callback The async function to determine which queue each value should be sent to.
94+ * @param n The maximum number of parallel executions (default: Queue.#batchCount).
95+ * @returns A tuple containing the two new queues.
96+ */
97+ usplit : < U , V = U > ( callback : ( v : T ) => Promise < [ U , 0 ] | [ V , 1 ] | undefined > , n ?: number ) => [ Queue < U > , Queue < V > ] ;
98+ /**
99+ * Merges the values from another queue into this queue.
100+ * @param q The queue to merge values from.
101+ * @returns A new queue containing the merged values.
102+ */
103+ umerge : ( q : Queue < T > ) => Queue < T > ;
104+ /**
105+ * Creates multiple clones of the queue.
106+ * @param count The number of clone queues to create (default: 2).
107+ * @returns An array of cloned queues.
108+ */
109+ clone : ( count ?: number ) => Queue < T > [ ] ;
110+ /**
111+ * Collects all the values in the queue into an array.
112+ * @returns A promise that resolves to an array containing all the values in the queue.
113+ */
114+ collect : ( ) => Promise < T [ ] > ;
126115}
127-
128- export { Queue as default } ;
116+ //#endregion
117+ export { Queue as default } ;
0 commit comments