File tree Expand file tree Collapse file tree 2 files changed +44
-4
lines changed Expand file tree Collapse file tree 2 files changed +44
-4
lines changed Original file line number Diff line number Diff line change 1
1
declare type AnyIterable < T > = Iterable < T > | AsyncIterable < T >
2
2
declare const Streams : {
3
+ parallelForEach < T > (
4
+ concurrency : number ,
5
+ func : ( data : T ) => Promise < void > ,
6
+ iterable : AsyncIterable < T >
7
+ ) : Promise < void >
3
8
parallelMap < T , R > (
4
9
concurrency : number
5
10
) : {
@@ -20,8 +25,26 @@ declare const Streams: {
20
25
func : ( data : T ) => R | Promise < R > ,
21
26
iterable : AnyIterable < T >
22
27
) : AsyncIterableIterator < R >
28
+ transform ( concurrency : number ) : {
29
+ < T , R > (
30
+ func : ( data : T ) => R | Promise < R > ,
31
+ iterable : AnyIterable < T >
32
+ ) : AsyncIterableIterator < R >
33
+ < T , R > (
34
+ func : ( data : T ) => R | Promise < R >
35
+ ) : ( iterable : AnyIterable < T > ) => AsyncIterableIterator < R >
36
+ }
37
+ transform < T , R > (
38
+ concurrency : number ,
39
+ func : ( data : T ) => R | Promise < R >
40
+ ) : ( iterable : AnyIterable < T > ) => AsyncIterableIterator < R >
41
+ transform < T , R > (
42
+ concurrency : number ,
43
+ func : ( data : T ) => R | Promise < R > ,
44
+ iterable : AnyIterable < T >
45
+ ) : AsyncIterableIterator < R >
23
46
}
24
- declare namespace Promises {
47
+ declare namespace Streams {
25
48
export { AnyIterable }
26
49
}
27
50
export = Streams
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
+ const { apply : ReflectApply } = Reflect
4
+
3
5
let _streamingIterables
4
6
/*@__NO_SIDE_EFFECTS__ */
5
7
function getStreamingIterables ( ) {
@@ -10,11 +12,26 @@ function getStreamingIterables() {
10
12
}
11
13
12
14
/*@__NO_SIDE_EFFECTS__ */
13
- function parallelMap ( concurrency , func ) {
15
+ async function parallelForEach ( concurrency , func , iterable ) {
16
+ for await ( const _ of parallelMap ( concurrency , func , iterable ) ) {
17
+ /* empty block */
18
+ }
19
+ }
20
+
21
+ /*@__NO_SIDE_EFFECTS__ */
22
+ function parallelMap ( ...args ) {
23
+ const streamingIterables = getStreamingIterables ( )
24
+ return ReflectApply ( streamingIterables . parallelMap , undefined , args )
25
+ }
26
+
27
+ /*@__NO_SIDE_EFFECTS__ */
28
+ function transform ( ...args ) {
14
29
const streamingIterables = getStreamingIterables ( )
15
- return streamingIterables . parallelMap ( concurrency , func )
30
+ return ReflectApply ( streamingIterables . transform , undefined , args )
16
31
}
17
32
18
33
module . exports = {
19
- parallelMap
34
+ parallelForEach,
35
+ parallelMap,
36
+ transform
20
37
}
You can’t perform that action at this time.
0 commit comments