Skip to content

Instantly share code, notes, and snippets.

@laverdet
Created March 30, 2011 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laverdet/893712 to your computer and use it in GitHub Desktop.
Save laverdet/893712 to your computer and use it in GitHub Desktop.
// 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();
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