polotek/procstreams — pull request #5 by jstewmon (2012-01-27 21:21:49+00:00)
Title: Follow node convention passing stderr before stdout

This is a nifty module. I was doing a bunch of custom cli work to interact with git and make in a project, and procstreams proved to be a useful replacement, allowing me to delete a bunch of code. I love deleting code!

But, I use the excellent async module to organize my callbacks. I usually just send the stderr and stdout to the async task callback. That callback follows the node convention of expecting the first parameter to contain any errors. So, to use procstreams with it, I have to do something like this:

```javascript
var dataSwapArgs = function(callback) {
return function(stdout, stderr) {
callback(stderr, stdout);
};
};
async.auto({
locals: function(callback) {
proc('git', [
'for-each-ref',
'--format={"objectname": "%(objectname:short)", "refname": "%(refname:short)", "upstream":"%(upstream:short)"}',
'refs/heads'
], gitProcOptions).data(dataSwapArgs(callback));
}
}, function(err, results) {
if(err) { console.error(err); }
else {
//...
}
});
```

This pull request changes the order of the arguments when _output is emitted. By passing stderr before stdout for the data method, the async task callback can be passed directly to the data method.