-
-
Save xk/2031338 to your computer and use it in GitHub Desktop.
a proper fibonacci server in node. with threads_a_gogo
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
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