jessetane / queue

Asynchronous function queue with adjustable concurrency
MIT License
764 stars 66 forks source link

params for job callback not documented #88

Open Sleepful opened 1 year ago

Sleepful commented 1 year ago

from the docs:

q.push(function (cb) {
  const result = 'two'
  cb(null, result)
})

so it is implied that the second parameter of cb should be the value that will end up on q.results, but what does the first parameter of cb mean (with null value in the example)?

I assume the first param would take an error if there was one. But I dunno.

mgrist commented 1 year ago

I was confused by this as well, I am glad I am not the only one. The documentation for this library isn't the greatest.

jessetane commented 1 year ago

back in the old days, before promises got popular, we used the callback pattern to write async code. this pattern was so universal at that time that it did not make sense to document it here. here's a reference if you're curious about the pattern: https://nodejs.dev/en/learn/javascript-asynchronous-programming-and-callbacks/#handling-errors-in-callbacks

jessetane commented 1 year ago

i'm hoping someone will come along and rewrite this module to be a bit more promise oriented since that's what most folks are using today... read #86 and send a pr!

mgrist commented 1 year ago

That makes sense. I read some of your other comments and I ended up using Promise.all() instead of the queue library, but it was fun to play around with. Thanks for the knowledge on the callback pattern though!