Skip to content

Instantly share code, notes, and snippets.

@xk
Forked from ry/fib.js
Created March 13, 2012 20:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xk/2031338 to your computer and use it in GitHub Desktop.
Save xk/2031338 to your computer and use it in GitHub Desktop.
a proper fibonacci server in node. with threads_a_gogo
var http = require('http')
var pool = require('threads_a_gogo').createPool(5).all.eval(fib);
function fib (n) {
if (n < 2) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}
var server = http.createServer(function(req, res) {
pool.any.eval('fib(40)', function (err, data) {
res.writeHead(200);
res.end(data + "\n");
});
});
server.listen(8000);
console.log("server online at http://localhost:8000/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment