Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const b = (x: T[]) => asParallel(ParallelGeneratorType.PromiseOfPromises, x)
const c = (x: T[]) => asParallel(ParallelGeneratorType.PromiseToArray, x)
function asParallel(type: ParallelGeneratorType, values: T[]): IParallelEnumerable {
const generator1 = () =>
values.map((value) => new Promise((resolve) => setTimeout(() => resolve(value), 10)))
const generator2 = () =>
new Promise((resolve) => setTimeout(() => resolve([... values]), 10))
const generator3 = async () =>
await generator1()
switch (type) {
case ParallelGeneratorType.ArrayOfPromises:
return fromParallel(type, generator1)
case ParallelGeneratorType.PromiseToArray:
return fromParallel(type, generator2)
case ParallelGeneratorType.PromiseOfPromises:
default:
return fromParallel(type, generator3)
}
}