Skip to content

reduce callback isn't really optional #1223

@asquared

Description

@asquared

What version of async are you using?
1.5.2 (but the offending code seems to still exist in master)

Which environment did the issue occur in (Node version/browser version)
node v0.10.29

What did you do? Please include a minimal reproducable case illustrating issue.
The documentation says the callback is optional, so I should be able to do:

const async = require('async');

var array = [1, 2, 3];
function reducer(memo, item, callback) {
        memo += item;
        console.log("sum is %d", memo);
        setImmediate(callback, null, memo);
}

async.reduce(array, 0, reducer);

What did you expect to happen?

sum is 1
sum is 3
sum is 6

What was the actual result?

sum is 1
sum is 3
sum is 6

.../node_modules/async/lib/async.js:380
            callback(err, memo);
            ^
TypeError: undefined is not a function
    at .../node_modules/async/lib/async.js:380:13
    at .../node_modules/async/lib/async.js:52:16
    at .../node_modules/async/lib/async.js:269:32
    at .../node_modules/async/lib/async.js:44:16
    at Object.<anonymous> (.../node_modules/async/lib/async.js:377:17)
    at Object.immediate._onImmediate (timers.js:354:16)
    at processImmediate [as _immediateCallback] (timers.js:336:15)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions