On Wednesday, November 14, 2012 at 11:29 AM, pie_lard wrote: > I think the problem with the examples you've posted there is that you are > creating a domain for every query() call and also having to remember to wrap > the callback in bind() or intercept(). That's too much of a burden for every > call - particularly when the official node docs imply that one simply has to > create a domain during the early stage of an incoming request and from then > on exceptions will be caught properly. > >
The danger of using a slide deck as a reference is that the examples are contrived to give me something simple to live-code to in a presentation. If you're willing to make liberal use of domain.bind(), there's no reason why you can't just have one domain for a whole class of requests and add long-lived connections to the domain directly (although then it becomes more important to analyze the lifecycle of the domains and ensure that you're disposing of them properly when they're no longer needed). It's worth mentioning that domains are simple objects and are pretty cheap to create -- mostly just the cost of creating a new EventEmitter and adding a couple closures to it. Unless your code is super-hot, it shouldn't add very much overhead to run a specific request in a domain. > I'm not a node expert but I can't help but wonder if domains would be easier > to use if they simply stayed in place across all callbacks and didn't have > this notion of 'owning' EventEmitters. That way all you would need to do is > install a domain and never have to worry about whether your pooled resources > are going to dump you into a different domain at some point. Essentially that's what uncaughtException does; the added value of domains is that it adds context to errors and lets you perform cleanup and recovery in a manner similar to what you'd get with exceptions in the synchronous case. > Maybe this would only work if node were to maintain a stack of domains - I'm > not sure of the implications of that. Domains can be nested -- only the current innermost domain will receive error events. This is handled by a stack internally to the domain code. You could get multiple listeners on a domain by adding additional listeners, although you'd have to clean them up at the end of the scope manually. Probably better just to create a new domain. > I realise I'm probably missing something important here ;) Either what I'm > suggesting wouldn't work or couldn't be easily implemented. I see there's > another discussion going on on this list about node modules that seem to be > alternatives to domains (or are they built on domains somehow?), > I'm aware of very few third-party modules taking advantage of domains so far. If anybody else knows of any, it would be awesome to hear about it. F -- 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