Because the calling code calls back with the error (e.g., https://github.com/BryanDonovan/node-simple-elasticsearch/blob/master/lib/client.js#L54), and it was easier to add the nextTick() stuff inside the validator function instead of in each caller. I previously had it purely synchronous.. but changed it because of this thread. That validator.js file is not exported in the npm.. it's private.
Here's the diff to the previous version: https://github.com/BryanDonovan/node-simple-elasticsearch/commit/2dc50f2b59c69ef070df26714a3456831feda618 -Bryan On Aug 22, 2013, at 11:22 AM, Scott González <[email protected]> wrote: > The success case is synchronous. It looks like there's nothing that ever > needs to be async in that function. Why does this take a callback instead of > just returning a boolean? > > > On Thu, Aug 22, 2013 at 2:08 PM, Bryan Donovan <[email protected]> wrote: > Cool. I've updated node-simple-elasticsearch to call back with errors > asynchronously: > https://github.com/BryanDonovan/node-simple-elasticsearch/blob/master/lib/validator.js > > (at least I think I did it right). > > Bryan > > > On Aug 22, 2013, at 9:49 AM, Scott González <[email protected]> wrote: > >> This is just the robustness principle/Postel's law: Be conservative in what >> you send, be liberal in what you accept. >> >> If you're implementing an API, you should be consistent. If you're consuming >> the API, you should be defensive. But honestly, people writing node modules >> should follow the node patterns and never mix sync and async behavior. >> >> >> On Thu, Aug 22, 2013 at 12:44 PM, Eldar <[email protected]> wrote: >> I always followed the simple rule "callback may be called at any time" and I >> was pretty happy so far. >> The resulting code is more portable and simpler. Just use tail recursive >> algorithms and be happy. >> >> вторник, 20 августа 2013 г., 21:47:22 UTC+4 пользователь Bryan Donovan >> написал: >> I have been writing node.js client code for a couple of years now, and have >> authored a couple open source libraries, but somehow I missed the memo >> telling me that I'm supposed to wrap 'synchrounous' callbacks in >> process.nextTick(). I kind-of understand why that is a best-practice, but >> what I don't understand is what the drawback is if you don't do it. >> >> For example, I write code like this all the time, and have never had a >> single problem with it: >> >> function getSomething(args, cb) { >> if (!args) { return cb(new Error('args required')); } >> if (!args.id) { return cb(new Error('args.id required')); } >> >> SomeDatabase.get({id: args.id}, cb); >> } >> >> What are the potential issues with not wrapping those arg checks in >> process.nextTick()? >> >> >> Thanks, >> >> Bryan >> >> -- >> -- >> 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. >> >> >> -- >> -- >> 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 a topic in the >> Google Groups "nodejs" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/nodejs/0TmVfX9z1R0/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> >> For more options, visit https://groups.google.com/groups/opt_out. > > > -- > -- > 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. > > > -- > -- > 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 a topic in the Google > Groups "nodejs" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/nodejs/0TmVfX9z1R0/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. -- -- 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.
