Created
October 9, 2020 15:10
-
-
Save Kannndev/7a0504cc6563cccbffe1a13df9c9af00 to your computer and use it in GitHub Desktop.
Node js thread blocking example
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
const express = require('express'); | |
const app = express(); | |
function getPi() { | |
let sum = 0; | |
for (let n = 0; n < 10000000000; n++) { | |
let mult = n % 2 === 0 ? 1 : -1; | |
sum += mult * (1 / (2 * n + 1)); | |
} | |
return sum * 4; | |
} | |
app.get('/', function (req, res) { | |
const pi = getPi(); | |
res.send(`Pi Value, ${pi}`); | |
}); | |
app.get('/hello', function (req, res) { | |
res.send(`hello world`); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment