Right, I get that.
On Sep 1, 2013, at 8:59 AM, dhruvbird <[email protected]> wrote:
> @Bryan: Be careful when using the EventEmitter like pattern because:
>
> var e = new ObjectDerivingFromEventEmitter()
> e.makeRequest(request_parameters);
> e.on('error', function() { });
>
> Now, if makeRequest() were to emit the 'error' event synchronously, the
> client code will not be able to catch it.
>
> Even worse is when e.makeRequest() returns a response object and the error is
> emitted on that response object. There is no way to catch this 'error' event
> but to raise it in nextTick().
>
>
>
> On Tuesday, August 20, 2013 11:12:35 AM UTC-7, Bryan Donovan wrote:
> Thanks Scott.
>
> That's basically what I had gathered from googling around. It seems to me
> like it's not necessary to wrap in nextTick for most cases then.
>
>
> On Aug 20, 2013, at 10:58 AM, Scott González <[email protected]> wrote:
>
>> The potential issue is if the person consuming your API expects the callback
>> to always be async:
>>
>> // kick off the async process as early as possible
>> doAsync( cb );
>> // do some slightly high cost prep work before the callback is invoked
>> prepareStateForCallbackWhileWaiting();
>>
>> Doing the prep work after the async call allows you to reduce the amount of
>> time needed between the start of this tick and the tick when the callback is
>> actually invoked. Interestingly, the reason some people don't like forcing
>> async is for performance gains when the operation can be sync.
>>
>> You're going to get lots of arguments on both sides.
>>
>>
>>
>> On Tue, Aug 20, 2013 at 1:47 PM, Bryan Donovan <[email protected]> wrote:
>> 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 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.