Nested domains or "How do I leave a domain"

57 views
Skip to first unread message

phidelta

unread,
Sep 14, 2012, 9:52:38 AM9/14/12
to nod...@googlegroups.com
Hi, 

I am really liking the new domains feature. However I have a question: "How do I leave a domain"

Is my undesrtanding correct?:

    function b(callback) {
      // I am running inside the domain created in a
      fs.readFile('some-file', 'utf-8', function(err, val) {
        // I am running inside the domain created in a
        if (err) return callback(err);
        callback(undefined, val.replace('A','B'));
      });
    }
    function a() {
      var d=domain.create();
      d.run(b.bind(null, callback))
    }
    function callback() {
      // I am running inside the domain created in a
    }

If so, then how do I leave a domain? Simply dispose of it? Then in which domain am I afterwards? Think nested domains. Am I in the one I was in before doing *domain.run()* in *a*?

I I'm wrong in my understanding, then how do I ensure that all my async calls/callbacks remain in the domain I created?

I would really appreciate if someone could explain this, since I am about to embark on some major efforts that would really benefit from using domains. Understanding how they work would be sort of fundamental ;)

Regards,
Philipp

Marco Rogers

unread,
Sep 15, 2012, 11:38:47 PM9/15/12
to nod...@googlegroups.com
Don't know if you were at Node Summercamp, but we talked a lot about domains. It's clear that there's lots of confusion about the semantics. I've got some of the same questions. I had planned on finally sitting down to explore them tomorrow. I can tell you that domains *are* nested. When you start a new domain, it goes on a stack. And when you close it, you are back in the previous domain.

:Marco
Reply all
Reply to author
Forward
0 new messages