sqlite-schema-syncer.js
function qParallel(funcs, count) {
    var length = funcs.length;
    if (!length) {
        return q([]);
    }

    if (count == null) {
        count = Infinity;
    }

    count = Math.max(count, 1);
    count = Math.min(count, funcs.length);

    var promises = [];
    var values = [];
    for (var i = 0; i < count; ++i) {
        var promise = funcs[i]();
        promise = promise.then(next(i));
        promises.push(promise);
    }

    return q.all(promises).then(function () {
        return values;
    });

    function next(i) {
        return function (value) {
            if (i == null) {
                i = count++;
            }

            if (i < length) {
                values[i] = value;
            }

            if (count < length) {
                return funcs[count]().then(next())
            }
        }
    }
}
function qParallel(funcs, count) {
    var length = funcs.length;
    if (!length) {
        return q([]);
    }

    if (count == null) {
        count = Infinity;
    }

    count = Math.max(count, 1);
    count = Math.min(count, funcs.length);

    var promises = [];
    var values = [];
    for (var i = 0; i < count; ++i) {
        var promise = funcs[i]();
        promise = promise.then(next(i));
        promises.push(promise);
    }

    return q.all(promises).then(function () {
        return values;
    });

    function next(i) {
        return function (value) {
            if (i == null) {
                i = count++;
            }

            if (i < length) {
                values[i] = value;
            }

            if (count < length) {
                return funcs[count]().then(next())
            }
        }
    }
}
function qParallel ( funcs , count ) { var length = funcs . length ; if ( ! length ) { return q ( [ ] ) ; } if ( count == null ) { count = Infinity ; } count = Math . max ( count , 1 ) ; count = Math . min ( count , funcs . length ) ; var promises = [ ] ; var values = [ ] ; for ( var i = 0 ; i < count ; ++ i ) { var promise = funcs [ i ] ( ) ; promise = promise . then ( next ( i ) ) ; promises . push ( promise ) ; } return q . all ( promises ) . then ( function ( ) { return values ; } ) ; function next ( i ) { return function ( value ) { if ( i == null ) { i = count ++ ; } if ( i < length ) { values [ i ] = value ; } if ( count < length ) { return funcs [ count ] ( ) . then ( next ( ) ) } } } }
Runs at most 'count' number of promise producing functions in parallel.
@param funcs
@param count
@returns {*}
Runs at most count number of promise producing functions in parallel .