|
@ -227,13 +227,16 @@ with a single error handler in a single place. |
|
|
var d = domain.create(); |
|
|
var d = domain.create(); |
|
|
|
|
|
|
|
|
function readSomeFile(filename, cb) { |
|
|
function readSomeFile(filename, cb) { |
|
|
fs.readFile(filename, d.intercept(function(er, data) { |
|
|
fs.readFile(filename, d.intercept(function(data) { |
|
|
|
|
|
// note, the first argument is never passed to the |
|
|
|
|
|
// callback since it is assumed to be the 'Error' argument |
|
|
|
|
|
// and thus intercepted by the domain. |
|
|
|
|
|
|
|
|
// if this throws, it will also be passed to the domain |
|
|
// if this throws, it will also be passed to the domain |
|
|
// additionally, we know that 'er' will always be null, |
|
|
|
|
|
// so the error-handling logic can be moved to the 'error' |
|
|
// so the error-handling logic can be moved to the 'error' |
|
|
// event on the domain instead of being repeated throughout |
|
|
// event on the domain instead of being repeated throughout |
|
|
// the program. |
|
|
// the program. |
|
|
return cb(er, JSON.parse(data)); |
|
|
return cb(null, JSON.parse(data)); |
|
|
})); |
|
|
})); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|