@Pedro: This is the nice thing about JavaScript, you can handle problems in 
lots of different ways. I'm just pointing out one alternative approach. 
EventEmitters make a lot more sense when you are trying to make reusable 
components, given the (very small) overhead they imply.

On Monday, February 25, 2013 1:58:08 PM UTC+1, Pedro Teixeira wrote:
>
> When I advised using an event emitter, I was referring to the exposed API, 
> which looked like what Glenn was asking about.
>
> That operation he mentioned can emit several different events throughout 
> time, and the best fit would be, in my opinion, an event emitter. It's 
> universally known to node programmers and makes the most sense, plus has 
> error handling built-in that is pluggable with domains if the API user 
> wishes to.
>
> When it comes to the *implementation* of the exposed API, sure, you can 
> use async if you like it, or any control-flow API, or just roll out your 
> own flow control thing, but that choice should never surface to the API 
> user.
>
> -- 
> Pedro
>
> On Monday, February 25, 2013 at 12:52 PM, Geerten van Meel wrote:
>
> No need for event emitters, you can do this entirely functional. For this 
> sorts of asynchroneous tasks, the "async" module comes to the rescue. 
>
> A possible implementation would use the "queue" function with a high value 
> for the concurrency of task procession. Whenever an error occurs, or you 
> retrieve your desired data, dump that in one (or two seperate) arrays. When 
> your queue is drained, your send both the errors and the results back.
>
> In regard to limiting the amount of errors, if your error array is too 
> long, you can just skip processing in the worker function. I,.e. a single 
> line of if (errors.length > 5) return callback(); at the beginning of your 
> worker function.
>
> Here's the documentation: https://github.com/caolan/async#queue
>
> Flow control, especially in the context of asynchroneous behaviour, is 
> something which you need to wrap your head around when working with node. 
> "async" is one of the most used packages that makes our lives easier for 
> tasks like this one.
>
> On Monday, February 25, 2013 10:57:52 AM UTC+1, Glenn Block wrote:
>
> Hello all
>
> Let's assume you have an API that results in a batch of HTTP calls which 
> fire async and which are not sequential. A constraint of the API is that 
> any errors that occur during the calls need to get returned to the user.
>
> How have you customarily designed this?
>
> One idea was something like the following
>
> function send(message, callback) {
> }
>
> where callback is function(error, results) {
> }
>
> In this case error if not null is a JSON object with a collection of child 
> objects with the errors.
>
> An alternative idea I had was to have an additional completion callback 
> per item.
>
> so:
>
> function send(message, completionCallback, itemCallback) {
> }
>
> This introduces a callback for each item that is processed. In this case 
> the completion callback has a single error if ANY errors occur while the   
> itemCallback has individual errors as they occur.
>
> This is useful for cases where you might want to stop further processing 
> if the number of errors is very high.
>
> Thoughts / Experiences?
> Glenn 
>
>
>
>  -- 
> -- 
> 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] <javascript:>
> To unsubscribe from this group, send email to
> [email protected] <javascript:>
> 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] <javascript:>.
> 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