import { ArgumentOutOfRangeException } from "../../shared" ; import { IAsyncEnumerable } from "../../types" ; import { BasicAsyncEnumerable } from "../BasicAsyncEnumerable" ; param element param count param delay returns export const repeatAsync = < TResult > ( element , count , delay ? ) : IAsyncEnumerable < TResult > => { if ( count < 0 ) { throw new ArgumentOutOfRangeException ( `count` ) ; } if ( delay ) { return repeat2 ( element , count , delay ) ; } else { return repeat1 ( element , count ) ; } } ; private const repeat1 = < T > ( element , count ) : IAsyncEnumerable < T > => { async function * iterator ( ) { for ( let i = 0 ; i < count ; i ++ ) { yield element ; } } return new BasicAsyncEnumerable ( iterator ) ; } ; private const repeat2 = < T > ( element , count , delay ) : IAsyncEnumerable < T > => { async function * iterator ( ) { for ( let i = 0 ; i < count ; i ++ ) { yield await new Promise < T > ( ( resolve ) => setTimeout ( ( ) => resolve ( element ) , delay ) ) ; } } return new BasicAsyncEnumerable ( iterator ) ; } ;