libs/scully/src/lib/utils/asyncPool.js
/**
 * takes an array, and runs **MaxParalellTasks** in paralell until all tasks are node
 * @param MaxParalellTasks
 * @param array
 * @param taskFn
 */
takes an array, and runs **MaxParalellTasks** in paralell until all tasks are node
@param MaxParalellTasks
@param array
@param taskFn
takes an array and runs ** MaxParalellTasks ** in paralell until all tasks are node @param MaxParalellTasks @param array @param taskFn
function asyncPool(MaxParalellTasks, array, taskFn) {
    return __awaiter(this, void 0, void 0, function* () {
        const ret = [];
        const executing = [];
        let logTime = performance.now();
        for (const item of array) {
            const p = taskFn(item);
            ret.push(p);
            const e = p.then(() => executing.splice(executing.indexOf(e), 1));
            e['item'] = item;
            executing.push(e);
            const now = performance.now();
            if (now - logTime > progressTime) {
                const tasksLeft = Math.max(array.length - ret.length, executing.length);
                printProgress(array.length + 1 - tasksLeft, 'Rendering Routes:', array.length);
                logTime = now;
            }
            if (executing.length >= MaxParalellTasks) {
                yield Promise.race(executing);
            }
        }
        while (executing.length > 0) {
            yield Promise.race([...executing, waitForIt(progressTime)]);
        }
        printProgress(array.length, 'Rendering Routes:', array.length);
        return Promise.all(ret);
    });
}
function asyncPool ( MaxParalellTasks , array , taskFn ) { return __awaiter ( this , void 0 , void 0 , function * ( ) { const ret = [ ] ; const executing = [ ] ; let logTime = performance . now ( ) ; for ( const item of array ) { const p = taskFn ( item ) ; ret . push ( p ) ; const e = p . then ( ( ) => executing . splice ( executing . indexOf ( e ) , 1 ) ) ; e [ 'item' ] = item ; executing . push ( e ) ; const now = performance . now ( ) ; if ( now - logTime > progressTime ) { const tasksLeft = Math . max ( array . length - ret . length , executing . length ) ; printProgress ( array . length + 1 - tasksLeft , 'Rendering Routes:' , array . length ) ; logTime = now ; } if ( executing . length >= MaxParalellTasks ) { yield Promise . race ( executing ) ; } } while ( executing . length > 0 ) { yield Promise . race ( [ ... executing , waitForIt ( progressTime ) ] ) ; } printProgress ( array . length , 'Rendering Routes:' , array . length ) ; return Promise . all ( ret ) ; } ) ; }
takes an array, and runs **MaxParalellTasks** in paralell until all tasks are node
 @param MaxParalellTasks
 @param array
 @param taskFn
takes an array and runs ** MaxParalellTasks ** in paralell until all tasks are node @param MaxParalellTasks @param array @param taskFn
/** inform used tasks are still running. */