On Thu, Aug 29, 2013 at 5:20 AM, Alvaro Mouriño <[email protected]> wrote:
> Hi list, > > I started working with NodeJS quite recently, even if at first I was a > little skeptical about it, after using it intensively for the last > couple of months I realized it's an amazing piece of technology. The > only thing that I miss from other frameworks is the concept of > thread-locals. > > After some time researching on this, a friend told me that this > behavior could be achieved using domains [0]. I built a small > framework, Kolba [1], as a proof of concept of how I see this being > implemented. I also wrote an article explaining this idea and > presenting some questions that I have. > > The main question that I want to ask here is: What am I missing? Why > is this undocumented? Are there any edge cases that I don't see, which > make this idea non-viable? > > Actually, the biggest problem I'm facing with the use of domain is the > suppression of exceptions. I may be using it wrong probably, which > leads to errors being silenced, but nothing regarding the emulation of > thread-locals. > Hey Alvaro, I think the big difference here is that variables are not necessarily domain-local and can be referenced outside a domain or even in multiple domains. This means that bad state can leak and cause an exception domino effect. In the Web server scenario, this could mean killing all currently executing requests in a cluster. You could certainly structure your application/module to mimic "request-local" behavior to an extent, but this isn't a pattern or guarantee Node is pushing out of the box with domains. The big benefit of domains is capturing execution state on uncaught exceptions, potentially allowing for a graceful shutdown and more helpful logging. That's how I'm using domains in Pipeworks[1] (an execution pipeline tool) and more recently, Argo[2] (an HTTP reverse proxy and origin server for APIs). So far, so good. In short, the idea of "request-local" variables isn't non-viable, just nearly impossible to guarantee; you have to rely on module dependents using the right patterns for your framework. [1] https://github.com/kevinswiber/pipeworks#pipelinefaultcallback [2] https://github.com/argo/argo/blob/master/example/cluster.js#L10-L22 -- Kevin Swiber Projects: https://github.com/kevinswiber Twitter: @kevinswiber -- -- 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.
