Re: [node-dev] Re: Request / Thread local storage

2012-08-02 Thread MikeS
> > Here's some working code: "use strict"; var domain = require('domain'); var assert = require('assert'); // Implement a session class that keeps track of async operations // Is uses a domain to handle errors in these operations function Session() { this.domain = domain.createDomain();

Re: [node-dev] Re: Request / Thread local storage

2012-08-02 Thread Isaac Schlueter
Mike, Can you share some actual code for a program that requires access to process.domain to work properly? I'm not getting it from the english description. On Wed, Aug 1, 2012 at 1:54 PM, MikeS wrote: > The work done in the new domain involves async callbacks (sometimes multiple > levels of t

Re: [node-dev] Re: Request / Thread local storage

2012-08-01 Thread MikeS
The work done in the new domain involves async callbacks (sometimes multiple levels of them.) They preserve the current domain (via the eventing system), but not the entire stack. On Wednesday, August 1, 2012 12:10:53 AM UTC-7, Isaac Schlueter wrote: > > MikeS, > > Why can't you just create th

Re: [node-dev] Re: Request / Thread local storage

2012-08-01 Thread Isaac Schlueter
MikeS, Why can't you just create the new domain, enter it, do the stuff, then exit it, and do the rest? When you enter/exit domains, it's a stack. So, when you exit one domain, you're back in the original one. On Tue, Jul 31, 2012 at 5:18 PM, MikeS wrote: >> Something I've found useful, just i

Re: [node-dev] Re: Request / Thread local storage

2012-07-31 Thread MikeS
> > Something I've found useful, just in the error handling, umm, domain, when > processing a set of work that will result in asynchronous callbacks (e.g. > web service calls) is to 1. Save off the current domain, which is the one associated with some HTTP request. 2. Create a new d

Re: [node-dev] Re: Request / Thread local storage

2012-07-11 Thread Elad Ben-Israel
On Wed, Jul 11, 2012 at 5:25 PM, Matt wrote: > On Tue, Jul 10, 2012 at 6:17 PM, Elad Ben-Israel > wrote: > >> Not sure exactly what use case Gaurav is interested in, but I was >> interested in this thread because I think there is an unmet need around >> logging which domain-attached context coul

Re: [node-dev] Re: Request / Thread local storage

2012-07-11 Thread Matt
On Tue, Jul 10, 2012 at 6:17 PM, Elad Ben-Israel wrote: > Not sure exactly what use case Gaurav is interested in, but I was > interested in this thread because I think there is an unmet need around > logging which domain-attached context could help solve (even a single > pointer to a global instan

Re: [node-dev] Re: Request / Thread local storage

2012-07-11 Thread James Howe
My first though on reading about Domains was also "yay, I can access request-specific state (for logging, bail-out on abort, etc.) without having to pass request objects through every single function in the codebase (including libraries unrelated to http servers)". There's definitely a desire t

Re: [node-dev] Re: Request / Thread local storage

2012-07-10 Thread Elad Ben-Israel
Not sure exactly what use case Gaurav is interested in, but I was interested in this thread because I think there is an unmet need around logging which domain-attached context could help solve (even a single pointer to a global instance). Logs are emitted everywhere across application (and library)

Re: [node-dev] Re: Request / Thread local storage

2012-07-10 Thread Isaac Schlueter
Consider this the opposite of a blessing. That is not only an undocumented feature, but an undocumented implementation detail of an experimental feature. You can pretty well be assured it will change in a future release. (Though, not in v0.8.x, which is API and ABI frozen.) The reason that it's

Re: [node-dev] Re: Request / Thread local storage

2012-07-10 Thread Elad Ben-Israel
Done a little bit of digging and found out the undocumented `process.domain`, which actually allows one to access the current domain from anywhere. This is very similar to "thread local storage", but it's way awesomer because it automatically traverses async calls. For example (node 0.8.2): ``` v

Re: [node-dev] Re: Request / Thread local storage

2012-07-04 Thread hasanyasin
@Ben: Awesome! @Gaurav: If this was really a joke, I am really naive! :p On Wed, Jul 4, 2012 at 6:19 AM, Ben Noordhuis wrote: > On Wed, Jul 4, 2012 at 6:02 AM, Gaurav Vaish > wrote: > >> > >> > (ThreadLocal: > http://docs.oracle.com/javase/6/docs/api/java/lang/ThreadLocal.html) > >> > >> I'm n

Re: [node-dev] Re: Request / Thread local storage

2012-07-04 Thread Ben Noordhuis
On Wed, Jul 4, 2012 at 6:02 AM, Gaurav Vaish wrote: >> >> > (ThreadLocal:http://docs.oracle.com/javase/6/docs/api/java/lang/ThreadLocal.html) >> >> I'm not sure what you mean. Are you talking about TLS in C/C++ or >> something in JS? > > Well, yes! Was that a boolean logic joke?

[node-dev] Re: Request / Thread local storage

2012-07-03 Thread hasanyasin
Oh, that I can tell :p I have given this just an example. It is not very useful to make requests accessible unless you want to run over each request object for some reason. It will also prevent garbage collection of call stacks and ram usage will increase rapidly on a real system. It was just a

[node-dev] Re: Request / Thread local storage

2012-07-03 Thread hasanyasin
Very sorry for my extreme naivety... On Wednesday, July 4, 2012 12:03:18 AM UTC-4, Gaurav Vaish wrote: > > Hi Elad, > > > As far as I know node does not support something like that. One idea > that > > came to mind is to add support for associating arbitrary context to a > > domain

[node-dev] Re: Request / Thread local storage

2012-07-03 Thread Gaurav Vaish
> var requests = []; > > http.Server(function(req, res) { >     // req and res are what you want, already provided. They are > request-local. >     requests.push(req); // here we provide a way for others to access this > private from outside. > > }); Well, there's a catch => How do the "outside" k

[node-dev] Re: Request / Thread local storage

2012-07-03 Thread Gaurav Vaish
Hi Elad, > As far as I know node does not support something like that. One idea that > came to mind is to add support for associating arbitrary context to a > domain and > extract it along the way. > > I was thinking on trying to hack somethin

[node-dev] Re: Request / Thread local storage

2012-07-03 Thread Gaurav Vaish
> > > (ThreadLocal:http://docs.oracle.com/javase/6/docs/api/java/lang/ThreadLocal.html) > > I'm not sure what you mean. Are you talking about TLS in C/C++ or > something in JS? Well, yes! -- Happy Hacking, Gaurav Vaish www.m10v.com

[node-dev] Re: Request / Thread local storage

2012-07-03 Thread hasanyasin
In JavaScript, everything is much simpler. In Node, there are no threads, no such problems. >From your question, especially "thread-local / request-local" I think you are talking about a server, maybe an http server, maybe another protocol. Either way, what you want is very simple in Node. For