Skip to content

Instantly share code, notes, and snippets.

@ejnshtein
Created February 24, 2020 21:58
Show Gist options
  • Save ejnshtein/371823253a7e4b65dfe9c7b3f6e713c9 to your computer and use it in GitHub Desktop.
Save ejnshtein/371823253a7e4b65dfe9c7b3f6e713c9 to your computer and use it in GitHub Desktop.
const Express = require('express')
const app = Express()
const sleep = timeout => new Promise(resolve => setTimeout(resolve, timeout))
async function getData () {
await sleep(400)
return 1
}
async function processData (data) {
await sleep(200)
return data * 2
}
app.get('/', async function (request, reply) {
const data = await getData()
const processed = await processData(data)
return processed
})
app.listen(3000, err => {
console.log(err || 'listening...')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment