Interesting question! I'm looking forward to the answer. Both streams and callbacks usually involve IO, but calculating prime number would not. So it might be a special case. But still interesting.
Steve On Fri, Apr 27, 2012 at 8:22 PM, Mark Volkmann <[email protected]>wrote: > This is a question about recommended usage in Node. > As an example, let's say I want to write a function that returns the > first n prime numbers. > I could write a function that takes n and a callback. > It could invoke the callback once for each prime number to be returned > and then invoke it with zero to signal the end. > > I could also write a function that takes n and returns a readable stream. > The caller could listen for data events (one per prime number to be > returned) > and an end event. > > I'm pretty sure the stream approach is preferred, > but would you say that the callback approach is wrong or at least > discouraged? > > -- > R. Mark Volkmann > Object Computing, Inc. > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
