On Monday, November 12, 2012 at 3:36 PM, pie_lard wrote:
> Cool - thanks!
>  
> This definitely could be better documented.  It's a pretty easy trap to fall 
> into.
>  
> Also, your solution still depends on process.domain which isn't mentioned 
> officially (ie. at http://nodejs.org/api/process.html ).
For that, I was just following your lead. I think the intent is that 
process.domain is meant to be used by library writers who want to make use of 
domains without directly depending on node 0.8+. There's also domain.active, 
for code that's built to be domain-aware from the get-go.

However, my assumption is that the typical domain pattern is going to look a 
lot more like:

var domain = require('domain');
// setup...

app.get('/thinger/:doer', function (req, res) {
  var d = domain.create();
  d.on('error', function (error) { /* oh no */ });
  d.run(function () {
    // do a buncha stuff
    db.query("SELECT * FROM foo WHERE ?", params, d.bind(function (err, rows, 
cols) {
      // handle
    });
  })
}

or, more succinctly (using domain.intercept, which is documented, but not with 
any particularly convincing motivation):

var domain = require('domain');
// setup...

app.get('/thinger/:doer', function (req, res) {
  var d = domain.create();
  d.on('error', function (error) { /* oh no */ });
  d.run(function () {
    // do a buncha stuff
    db.query("SELECT * FROM foo WHERE ?", params, d.intercept(function (rows, 
cols) {
      // handle
    });
  })
}



I gave a little talk on domains last week, and my slides are here: 
http://othiym23.github.com/domainion/

It's my first cut at this material and tries to put all this in context, and 
might help you figure out what's going on a little better.

F

Forrest L Norvell
Node.js agent engineer
| E forr...@newrelic.com (mailto:forr...@newrelic.com) | C (415) 823-6356 | T 
@othiym23 (http://twitter.com/othiym23) | G github.com/othiym23 
(https://github.com/othiym23) | W newrelic.com (http://newrelic.com/)
( ( *))  New Relic  



-- 
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

Reply via email to