diff options
author | Ryan <ry@tinyclouds.org> | 2009-06-28 19:05:58 +0200 |
---|---|---|
committer | Ryan <ry@tinyclouds.org> | 2009-06-28 19:08:27 +0200 |
commit | 65324866bcfa72b8ed934e081ac7ef239f3a819b (patch) | |
tree | 01f5e15386e35c03ef31e6290354686d785d3c1b /src/node.js | |
parent | 7cd09874c666f0ce64b1d7776de74f55ff3e53ab (diff) | |
download | nodejs-65324866bcfa72b8ed934e081ac7ef239f3a819b.tar.gz nodejs-65324866bcfa72b8ed934e081ac7ef239f3a819b.tar.bz2 nodejs-65324866bcfa72b8ed934e081ac7ef239f3a819b.zip |
Implement Promises for file i/o
Diffstat (limited to 'src/node.js')
-rw-r--r-- | src/node.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/node.js b/src/node.js index 0c956a9a5..5335d611c 100644 --- a/src/node.js +++ b/src/node.js @@ -72,7 +72,7 @@ node.path = new function () { node.cat = function(location, encoding, callback) { var url_re = new RegExp("^http:\/\/"); var f = url_re.exec(location) ? node.http.cat : node.fs.cat; - f(location, encoding, callback); + return f(location, encoding, callback); }; // Module @@ -105,12 +105,14 @@ node.Module.prototype.load = function (callback) { throw "Module '" + self.filename + "' is already loaded."; } - node.cat(self.filename, "utf8", function (status, content) { - if (status != 0) { - stderr.puts("Error reading " + self.filename); - node.exit(1); - } + var promise = node.cat(self.filename, "utf8"); + + promise.addErrback(function () { + stderr.puts("Error reading " + self.filename); + node.exit(1); + }); + promise.addCallback(function (content) { self.target.__require = function (path) { return self.newChild(path, {}); }; self.target.__include = function (path) { self.newChild(path, self.target); }; |