remarks Used with  Async . mapAsync and  Async . forEachAsync .
 *
 *  beta export interface IAsyncParallelismOptions { /**
     * Optionally used with the   Async . mapAsync and  Async . forEachAsync * to limit the maximum number of concurrent promises to the specified number.
      concurrency ? : number ; } beta export class Async { remarks This API is similar to the system `Array#map`, except that the loop is asynchronous,
     * and the maximum number of concurrent promises can be throttled
     * using  IAsyncParallelismOptions . concurrency .
     *
     * If `callback` throws a synchronous exception, or if it returns a promise that rejects,
     * then the loop stops immediately.  Any remaining array items will be skipped, and
     * overall operation will reject with the first error that was encountered.
     *
     *  param iterable param callback param options returns public static async mapAsync < TEntry , TRetVal > ( iterable , callback , options ? ) { const result = [ ] ; await Async . forEachAsync ( iterable , async ( item , arrayIndex ) : Promise < void > => { result [ arrayIndex ] = await callback ( item , arrayIndex ) ; } , options ) ; return result ; } remarks This API is similar to the system `Array#forEach`, except that the loop is asynchronous,
     * and the maximum number of concurrent promises can be throttled
     * using  IAsyncParallelismOptions . concurrency .
     *
     * If `callback` throws a synchronous exception, or if it returns a promise that rejects,
     * then the loop stops immediately.  Any remaining array items will be skipped, and
     * overall operation will reject with the first error that was encountered.
     *
     *  param iterable param callback param options public static async forEachAsync < TEntry > ( iterable , callback , options ? ) { await new Promise < void > ( ( resolve , reject ) => { const concurrency = options ?. concurrency && options . concurrency > 0 ? options . concurrency : Infinity ; let operationsInProgress = 0 ; const iterator = ( ( iterable as Iterable < TEntry > ) [ Symbol . iterator ] || ( iterable as AsyncIterable < TEntry > ) [ Symbol . asyncIterator ] ) . call ( iterable ) ; let arrayIndex = 0 ; let iteratorIsComplete = false ; let promiseHasResolvedOrRejected = false ; async function queueOperationsAsync ( ) { while ( operationsInProgress < concurrency && ! iteratorIsComplete && ! promiseHasResolvedOrRejected ) { const currentIteratorResult = await iterator . next ( ) ; iteratorIsComplete = ! ! currentIteratorResult . done ; if ( ! iteratorIsComplete ) { operationsInProgress ++ ; Promise . resolve ( callback ( currentIteratorResult . value , arrayIndex ++ ) ) . then ( async ( ) => { operationsInProgress -- ; await onOperationCompletionAsync ( ) ; } ) . catch ( ( error ) => { promiseHasResolvedOrRejected = true ; reject ( error ) ; } ) ; } } if ( iteratorIsComplete ) { await onOperationCompletionAsync ( ) ; } } async function onOperationCompletionAsync ( ) { if ( ! promiseHasResolvedOrRejected ) { if ( operationsInProgress === 0 && iteratorIsComplete ) { promiseHasResolvedOrRejected = true ; resolve ( ) ; } else if ( ! iteratorIsComplete ) { await queueOperationsAsync ( ) ; } } } queueOperationsAsync ( ) . catch ( ( error ) => { promiseHasResolvedOrRejected = true ; reject ( error ) ; } ) ; } ) ; } /**
     * Return a promise that resolves after the specified number of milliseconds.
     */ public static async sleep ( ms ) { await new Promise ( ( resolve ) => { setTimeout ( resolve , ms ) ; } ) ; } }