Skip to content

Instantly share code, notes, and snippets.

@Kannndev
Created October 9, 2020 15:10
Show Gist options
  • Save Kannndev/7a0504cc6563cccbffe1a13df9c9af00 to your computer and use it in GitHub Desktop.
Save Kannndev/7a0504cc6563cccbffe1a13df9c9af00 to your computer and use it in GitHub Desktop.
Node js thread blocking example
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