On Wednesday, November 14, 2012 at 4:01 PM, pie_lard wrote: > On Wednesday, 14 November 2012 23:43:27 UTC, Forrest L Norvell wrote: > > How does that persistence work? Put differently, how is Node supposed to > > know when a given EE is participating in a domain? You and I know that each > > individual node-mysql connection only handles a single query / response at > > a time, but other modules are going to multiplex on event emitters, and > > then you have to deal with the problem of figuring out which callback to > > associate with which domain. > > > So, for example, node-mysql could be receiving callbacks because data has > arrived on a socket (or something like that - haven't looked and haven't done > any low-level IO in node ;) ). And perhaps that data may turn out to be part > of the response to one of several in-flight queries (this is all > hypothetical). So I guess node-mysql would in that case have to track > domains itself - that is, when query() is called by end-user code it would > have to store the value of process.domain along with whatever it needs to > track the call.
If you look at how domain.bind() is implemented (https://github.com/joyent/node/blob/v0.8/lib/domain.js#L148-L207), it wraps a closure around its callback, and all that closure does is ensure that process.domain and domain.active are set to the correct domain via domain.enter() (and cleared via domain.exit()) correctly before the callback is invoked. In effect, it's doing exactly what you describe, but in a DRY, general way. > My point is that (a) that still doesn't involve binding a node-mysql > connection to a particular domain, which wouldn't help afaict and (b) many > modules presumably wouldn't have to do this if they aren't multiplexing > results in this way (I guess most aren't). In this case, binding a connection to a domain would definitely lead to incorrect behavior. I think in the vast majority of these cases domain.bind() is the best way ensure callbacks are evaluated in the correct domain. I apologize if I muddied the waters by bringing it up in the first place. ;) > Sorry if this is all getting a bit long-winded. I think I'm getting my head > around domains anyway! I think that domains are going to remain obscure until enough people have banged their heads against them to figure out whether or not they're valuable, so conversations like this are useful. I apologize for taking such a long and roundabout way to explain things. 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 [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
