lib/Function.js
/**
 * Wraps a task into another one that will execute the wrapt task repeadedly in series with given conditions and collects results into a new array.
 *
 * @param {number|function(i,res)} [times]
 *  Wrapt task will be executed 'times' times before returning the results if no error occurs.
 *  If 'times' is a function then it will be called with the count of repeats and the result of previous execution in every round
 *  until it returns a number greather than zero or any truthy value.
 * @returns {task(done)}
 */
Wraps a task into another one that will execute the wrapt task repeadedly in series with given conditions and collects results into a new array.
@param {number|function(i,res)} [times]
Wrapt task will be executed 'times' times before returning the results if no error occurs.
If 'times' is a function then it will be called with the count of repeats and the result of previous execution in every round
until it returns a number greather than zero or any truthy value.
Wraps a task into another one that will execute the wrapt task repeadedly in series with given conditions and collects results into a new array . @param { number|function ( i res ) } [ times ] Wrapt task will be executed ' times ' times before returning the results if no error occurs . If ' times ' is a function then it will be called with the count of repeats and the result of previous execution in every round until it returns a number greather than zero or any truthy value .
function repeatSeries(times) {
    assert(!arguments.length || !isNaN(+times) || times instanceof Function, 'If provided, first argument of <task>.repeat([times]) must be a number or function.')
    if(!arguments.length)
        times = 1
    if(!(times instanceof Function))
        times = (function (i) { return this - i }).bind(+times)
    var fn = this
    return decorateTask(function (done, recall) {
        var result = [], i = 0
        function next(err, res) {
            if(err)
                done(err)
            else {
                result.push(res)
                if(Math.max(Math.round(+times(i++, res) || 0), 0))
                    fn(next, true)
                else
                    done(null, result)
            }
        }
        fn(next, true)
    }, true, fn.abort)
}
function repeatSeries ( times ) { assert ( ! arguments . length || ! isNaN ( + times ) || times instanceof Function , 'If provided, first argument of <task>.repeat([times]) must be a number or function.' ) if ( ! arguments . length ) times = 1 if ( ! ( times instanceof Function ) ) times = ( function ( i ) { return this - i } ) . bind ( + times ) var fn = this return decorateTask ( function ( done , recall ) { var result = [ ] , i = 0 function next ( err , res ) { if ( err ) done ( err ) else { result . push ( res ) if ( Math . max ( Math . round ( + times ( i ++ , res ) || 0 ) , 0 ) ) fn ( next , true ) else done ( null , result ) } } fn ( next , true ) } , true , fn . abort ) }
Wraps a task into another one that will execute the wrapt task repeadedly in series with given conditions and collects results into a new array.
Wraps a task into another one that will execute the wrapt task repeadedly in series with given conditions and collects results into a new array .