Created
March 30, 2011 01:44
-
-
Save laverdet/893712 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Bad third-party code | |
var fs = require('fs'); | |
require('fibers'); | |
function fetchSomething() { // don't do this! | |
var fiber = Fiber.current; | |
fs.readFile(__filename, 'utf8', function(err, val) { | |
fiber.run(val); | |
}); | |
return Fiber.yield(); | |
} | |
// Naive client code | |
console.log('I am innocent code!'); | |
var data = fetchSomething(); |
This file contains hidden or 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
I am innocent code! | |
node.js:178 | |
throw e; // process.nextTick error, or 'error' event on first tick | |
^ | |
Error: yield() called with no fiber running | |
at fetchSomething (./evil.js:10:15) | |
at Object.<anonymous> (./evil.js:15:12) | |
at Module._compile (module.js:404:26) | |
at Object..js (module.js:410:10) | |
at Module.load (module.js:336:31) | |
at Function._load (module.js:297:12) | |
at Array.<anonymous> (module.js:423:10) | |
at EventEmitter._tickCallback (node.js:170:26) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment