Created
February 1, 2010 23:51
-
-
Save creationix/292192 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.mixin(require('sys')); | |
valid_modes = ["r", "w", "a"]; | |
var File = { | |
open: function (filename, mode) { return function (callback) { | |
debug("in open closure"); | |
mode = mode || "w"; | |
if (valid_modes.indexOf(mode) < 0) { | |
throw new Error("Invalid file mode " + JSON.stringify(mode)); | |
} | |
if (!filename) { | |
throw new Error("Must specify a filename"); | |
} | |
setTimeout(function () { | |
if (filename !== "test.txt") { | |
throw new Error("File not found " + filename); | |
} | |
callback(1) | |
}, 100); | |
}}, | |
}; | |
try { | |
debug("About to call open (no errors expected)"); | |
File.open("test.txt")(function (fd) { | |
debug("Done, no errors"); | |
}); | |
} catch(e) { | |
debug("Block 1: " + e.stack); | |
} | |
try { | |
debug("About to call open (immediete error expected)"); | |
File.open("test.txt", "z")(function (fd) { | |
debug("Done, no errors"); | |
}); | |
} catch(e) { | |
debug("Block 2: " + e.stack); | |
} | |
try { | |
debug("About to call open (delayed error expected)"); | |
File.open("badname.txt")(function (fd) { | |
debug("Done, no errors"); | |
}); | |
} catch(e) { | |
debug("Block 3: " + e.stack); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEBUG: About to call open (no errors expected) | |
DEBUG: in open closure | |
DEBUG: About to call open (immediete error expected) | |
DEBUG: in open closure | |
DEBUG: Block 2: Error: Invalid file mode "z" | |
at /Users/tim/Code/jack/async.js:10:13 | |
at Object. (/Users/tim/Code/jack/async.js:36:28) | |
at [object Object]. (node.js:932:23) | |
at [object Object].emitSuccess (node.js:244:15) | |
at [object Object]. (node.js:657:21) | |
at [object Object].emitSuccess (node.js:244:15) | |
at node.js:514:29 | |
at node.js:989:9 | |
DEBUG: About to call open (delayed error expected) | |
DEBUG: in open closure | |
DEBUG: Done, no errors | |
Error: File not found badname.txt | |
at Timer. (/Users/tim/Code/jack/async.js:17:15) | |
at node.js:989:9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment