Created
September 27, 2019 14:26
-
-
Save sudhakar3697/b41daca06b06e08c2a2e38392b76e27a to your computer and use it in GitHub Desktop.
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() | |
const port = 2709 | |
app.get('/home', (req, res) => res.send('Hello Zetwerk')) | |
app.get('/test', async (req, res) => { | |
await doSomeLongOperation(); | |
res.send('Operation is done') | |
}) | |
app.use(function (req, res, next) { | |
res.status(404).send('Sorry can\'t find that!') | |
}) | |
async function doSomeLongOperation() { | |
for (let i = 0; i < 5000000000000; i++) { | |
console.log(await square(i)) | |
} | |
} | |
async function square(i) { | |
return new Promise(resolve => setTimeout(function () { | |
resolve(i*i) | |
}, 1000) | |
) | |
} | |
app.listen(port, () => console.log(`App listening on port ${port}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If we want to do some complex operation instead of the square function, we can offload it by using worker threads | child process | cluster | N-API native node addons (C/C++).