The first call to addasync is running in sync way (hmmm... I should write a better explanation, but my English is limited ;-)...) Then, it prints the first 3. The call to addsyn is runnning after that, then it prints the 6 Meanwhile, the first addasync queued a new call in process.nextTick. In the next tick, that call will be run, producing the second 3
Make sense? On Wed, Jun 6, 2012 at 10:31 AM, Anand George <mranandgeo...@gmail.com>wrote: > Hi! > > Have been reading up on process.nextTick and found this one rather odd. > It's forcing the calling function to run again. > > function addasync(no1, no2, result) > { > res = no1 + no2; > this.result = result(false, res); > process.nextTick(function() { > this.result = result(true, res); > }); > }; > > addasync(1, 2, function(err, res) { > console.log(res); > }); > > function addsync(no1, no2) { > return (no1 + no2); > } > > console.log(addsync(4, 2)); > > When I run this code I get the following output. > > 3 > 6 > 3. > > Any ideas why this could be happening. > > -- > 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 nodejs@googlegroups.com > To unsubscribe from this group, send email to > nodejs+unsubscr...@googlegroups.com > 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 nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en