-
Notifications
You must be signed in to change notification settings - Fork 18
/
fromParallel.ts
43 lines (40 loc) · 1.62 KB
/
fromParallel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { IParallelEnumerable, ParallelGeneratorType } from "../../types"
import { BasicParallelEnumerable } from "../BasicParallelEnumerable"
type FromParallelFunc = {
/**
* Creates an IParallelEnumerable from a function that returns an Array of Promises
* @param type Array of Promises
* @param generator Function that gives back an array of promises
* @returns IParallelEnumerable<T>
*/
<TSource>(
type: ParallelGeneratorType.ArrayOfPromises,
generator: () => Promise<TSource>[]): IParallelEnumerable<TSource>
/**
* Creates an IParallelEnumerable from a function that returns a Array Promise
* @param type Promise to Array
* @param generator Async function which returns an array of values
* @returns IParallelEnumerable<T>
*/
<TSource>(
type: ParallelGeneratorType.PromiseToArray,
generator: () => Promise<TSource[]>): IParallelEnumerable<TSource>
/**
* Creates an IParallelEnumerable from a function that returns an promise of an promise array of valus
* @param type Promise of Promises
* @param generator Async function that returns an array of value promises
* @returns IParallelEnumerable<T>
*/
<TSource>(
type: ParallelGeneratorType.PromiseOfPromises,
generator: () => Promise<Promise<TSource>[]>): IParallelEnumerable<TSource>
}
export const fromParallel: FromParallelFunc = <TSource>(
type: any,
generator: () => any) => {
return new BasicParallelEnumerable<TSource>({
generator,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
type,
})
}