Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
doc: fix domains example
Browse files Browse the repository at this point in the history
Need `utf8` encoding for JSON.parse and fix to avoid JSON.parse error when only
one argument is passed in domain.bind
  • Loading branch information
Shigeki Ohtsu authored and bnoordhuis committed Jul 30, 2012
1 parent b3cf3f3 commit 5b37da2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions doc/api/domain.markdown
Expand Up @@ -198,9 +198,9 @@ thrown will be routed to the domain's `error` event.
var d = domain.create();

function readSomeFile(filename, cb) {
fs.readFile(filename, d.bind(function(er, data) {
fs.readFile(filename, 'utf8', d.bind(function(er, data) {
// if this throws, it will also be passed to the domain
return cb(er, JSON.parse(data));
return cb(er, data ? JSON.parse(data) : null);
}));
}

Expand All @@ -227,7 +227,7 @@ with a single error handler in a single place.
var d = domain.create();

function readSomeFile(filename, cb) {
fs.readFile(filename, d.intercept(function(data) {
fs.readFile(filename, 'utf8', 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.
Expand Down

0 comments on commit 5b37da2

Please sign in to comment.