Am 02.02.2013 um 20:21 schrieb Jake Verbaten <[email protected]>:

> triggering an error when done is called more times then expected is a 
> difficult design. 

Error callback is called same amount of times as an error happens, because 
there might be different errors. Also errors are accumulated in one array for 
the case you want to handle once all errors of one Do instance.

> 
> If you call the callback once saying 'your done' and then again with an error 
> saying 'woh, it was called too many times' then you break the environment of 
> a callback being called once. If you throw, your being a dick and crashing 
> the process in production. If you emit an error then the result has to be an 
> EventEmitter and you have to document said error.

There is no "done" callback, there are "success" and "error" callbacks. 
"success" is called only once.

There are only 2 case where "Do" will throw: 
    1. you have got an error but you haven't defined an error callback
    2. you are done, but you haven't defined a success callback

If "done" called more times than expected - it is an error passed to the error 
callback. If the callback is not defined - see point 1.

I wanted to keep it really lightweight so haven't used EventEmitter. Also there 
is no need to attach multiple error and success callbacks.

In both cases I could ignore missing callbacks and NOT throw, but I don't want 
to encourage ignore errors. No real code should do this. At the end if you want 
to ignore all errors, just pass a noop fn. If someone ignores error and success 
callbacks - he is a dick and his process should crash.

> 
> The error of done being called too many times is also difficult to recover 
> from because you already did the thing when your done.


You can log it and investigate later using stacktrace how this could happen. At 
the end the same thing happens if you don't use "Do" ...


> As for messing with the count ( 
> https://github.com/Raynos/after/blob/master/lib/after.js#L4 ). It's just a 
> numeric property, mutate it if it matches your use case. I think its bad to 
> mutate it.

You don't know always at the beginning of your function how much async 
operations you will have. It CAN conditionally change after some async tasks 
are done.


> 
> 
> On Sat, Feb 2, 2013 at 1:02 AM, Oleg Slobodskoi <[email protected]> 
> wrote:
> Haha, never seen "after", but the idea is similar,
> 
> however "do" handles more cases:
> 
> - increate later todo amount 
>     - if the code is complicated, you don't want (or you can't) to set the 
> amount of todos at the beginning, but conditionally increment them
> - it triggers an error if "done"  is called more times than expected
> 
> and still almost 0 overhead.
> 
> 
> Am 02.02.2013 um 06:09 schrieb Jake Verbaten <[email protected]>:
> 
>> This is just a way more complex version of Raynos/after. 
>> (http://github.com/Raynos/after)
>> 
>> On Jan 31, 2013 9:47 AM, "Oleg Slobodskoi" <[email protected]> wrote:
>> If you don't want to use all the async/steper libraries but just want a 
>> reliable way to know when the function is done - this is for you.
>> 
>> https://github.com/kof/do
>> Feedback welcome.
>> 
>> Oleg Slobodskoi
>> 
>> @oleg008
>> 
>> 
>> -- 
>> -- 
>> 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 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 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 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 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.


Reply via email to