Skip to content

Instantly share code, notes, and snippets.

@brianc
Created March 14, 2013 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianc/5165396 to your computer and use it in GitHub Desktop.
Save brianc/5165396 to your computer and use it in GitHub Desktop.
var pg = require('pg');
for(var i = 0; i < 10; i++) {
var domain = require('domain').create();
domain.id = i;
domain.count = 0;
domain.run(λ() {
process.domain.count++;
pg.connect(λ(err, client, done) {
process.domain.count++;
setTimeout(λ() {
process.domain.count++;
client.query('SELECT NOW()', λ() {
process.domain.count++;
done();
console.log('%d - %d', process.domain.id, process.domain.count)
})
})
})
})
}
//output:
bmc@bmcnix:~$ node domain-example.js
0 - 5
1 - 4
2 - 4
3 - 4
4 - 4
5 - 4
6 - 4
7 - 4
8 - 4
0 - 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment