Calling:
poof( function (err) { console.log(err ? err : 'done'); });
Expected Result:
empty array
done
Actual Result:
empty array
items: undefined
cb: undefined
[TypeError: undefined is not a function]
var q = require('queue-flow'); | |
function asyncEmptyArray (args, callback) { | |
console.log('empty array'); | |
callback(null, []); | |
} | |
function poof (callback) { | |
q([null]) | |
.node(asyncEmptyArray, callback) | |
.node(function (items, cb) { | |
console.log('items: ' + JSON.stringify(items)) | |
console.log('cb: ' + cb) | |
cb(); | |
}, callback) | |
.on('close', function () { callback(); }); | |
} |
Calling:
poof( function (err) { console.log(err ? err : 'done'); });
Expected Result:
empty array
done
Actual Result:
empty array
items: undefined
cb: undefined
[TypeError: undefined is not a function]
Here's the reason why it didn't work:
.node
can take in an array and treat that array as the set of arguments it should parse (excluding the callback at the end). If you want your only argument to be an array of values, you need to wrap it in an array, as well.
Will fork this gist with a solution.
The asyncEmptyArray function isn't returning an error, so why would you expect it to call your error function?
Sorry, the example was confusing.
In .node(asyncEmptyArray, callback)
, I don't expect callback to be called, it can be replaced withfunction(e) { console.log('blah'); }
without changing the test results. I see your solution though. Thanks!
I admit it's not behaving as expected, here, but I'm puzzled by your expected result. The
asyncEmptyArray
function isn't returning an error, so why would you expect it to call your error function?