import { wait } from './wait' ; param fn param limit returns export function asyncLimiting < T extends ( ... args : any [ ] ) => Promise < any > > ( fn , limit ) { let execCount = 0 ; return async function ( ... args ) { await wait ( ( ) => { const res = execCount < limit ; if ( res ) { execCount ++ ; } return res ; } ) ; try { return await fn ( ... args ) ; } finally { execCount -- ; } } as T ; }