import { ArgumentOutOfRangeException } from "../../shared" ; import { IParallelEnumerable , ParallelGeneratorType } from "../../types" ; import { BasicParallelEnumerable } from "../BasicParallelEnumerable" ; param element param count param delay returns export const repeatParallel = < TResult > ( element , count , delay ? ) : IParallelEnumerable < TResult > => { if ( count < 0 ) { throw new ArgumentOutOfRangeException ( `count` ) ; } if ( delay ) { return repeat2 ( element , count , delay ) ; } else { return repeat1 ( element , count ) ; } } ; const repeat1 = < T > ( element , count ) : IParallelEnumerable < T > => { const generator = async ( ) => { const values = new Array < T > ( count ) ; for ( let i = 0 ; i < count ; i ++ ) { values [ i ] = element ; } return values ; } ; return new BasicParallelEnumerable ( { generator , type : ParallelGeneratorType . PromiseToArray , } ) ; } ; const repeat2 = < T > ( element , count , delay ) : IParallelEnumerable < T > => { const generator = async ( ) => { const values = new Array < Promise < T > > ( count ) ; for ( let i = 0 ; i < count ; i ++ ) { values [ i ] = new Promise < T > ( ( resolve ) => setTimeout ( ( ) => resolve ( element ) , delay ) ) ; } return values ; } ; return new BasicParallelEnumerable < T > ( { generator , type : ParallelGeneratorType . PromiseOfPromises , } ) ; } ;