gulpjs / async-done

Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.
MIT License
69 stars 21 forks source link

problem with arguments idea #23

Closed tunnckoCore closed 9 years ago

tunnckoCore commented 9 years ago

Problem is that index.js#L26 limit us. Currently that limit us to pass only one value to the callback e.g.

asyncDone(function (done) {
  done(null, 123);
}, function(err, res) {
  console.log(res)
  //=> 123
})

but you cant

asyncDone(function (done) {
  done(null, 123, 456);
}, function(err, res) {
  console.log(res)
  //=> 123
})

One way to fix it is to be 1:1 relation

asyncDone(function (done) {
  done(null, 123, 456);
}, function(err, foo, bar) {
  console.log(foo) //=> 123
  console.log(bar) //=> 456
})

to do it we should change done fn to this

function done(){
  d.removeListener('error', onError);
  d.exit();

  return cb.apply(null, arguments);
}

Or other way is like .then do it - single array with values.

asyncDone(function (done) {
  done(null, 123, 456);
}, function(err, results) {
  console.log(results)
  //=> [123, 456]
})
tunnckoCore commented 9 years ago

Im more for 1:1

tunnckoCore commented 9 years ago

/cc @phated ? as per https://github.com/tunnckoCore/benz

phated commented 9 years ago

Published 1:1 in version 1.1.0