Keep in mind that callbacks don't necessarily go hand in hand with asynchroneous behaviour and most certainly don't mean the same (see Array.forEach vs process.nextTick).
Using callbacks (heavily) is a programming pattern that is used a lot in node. Just for this reason, a lot of npm modules that would usually perform strictly synchroneous tasks offer an api to allow for asynchroneous usage although there is no strict need for it. If you code isn't shared, don't bother. There is nothing wrong with working synchroneously with heavy computational tasks. Depending on your application this may however result in your event loop being blocked - depending on how heavy your computation tasks are - resulting i.e. in that your webserver does not respond to requests in a timely fashion. If that is the case, rethink your application design; Some ideas for dealing with heavy computational tasks were mentioned in this thread. Geerten On Wednesday, April 10, 2013 12:02:44 AM UTC+2, Mil Werns wrote: > > I have a simple question: When should I use callbacks? > > Currently, I'm only using callbacks in I/O cases (file, database and > network access). > My application has to iterate over a lot of big arrays and combines this > data to new objects. I'm doing this with a standard (synchronous) for-loop, > because this task needs only CPU power. So there would be no benefit to use > an asynchronous call. > > Is this assumption correct? > Can you please give me other examples for useful callbacks other than > those mentioned above? > > Thank you > -- -- 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 --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
