Skip to content

Instantly share code, notes, and snippets.

@jingidy
Created June 27, 2013 19:07
Show Gist options
  • Save jingidy/5879399 to your computer and use it in GitHub Desktop.
Save jingidy/5879399 to your computer and use it in GitHub Desktop.
Queue-flow 2nd node unexpectedly called with undefined parameters.
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]
@dfellis
Copy link

dfellis commented Jun 27, 2013

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?

@dfellis
Copy link

dfellis commented Jun 27, 2013

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.

@dfellis
Copy link

dfellis commented Jun 27, 2013

Will fork this gist with a solution.

@jingidy
Copy link
Author

jingidy commented Jun 27, 2013

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment