Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const makeAsync = require('es6-async')
- const timeout = (milliseconds) => new Promise(resolve => setTimeout(resolve, milliseconds))
- const random = () => Promise.resolve(Math.random())
- const asyncFunc = makeAsync(function* () {
- yield timeout(1000)
- return yield random()
- })
- module.exports.randomGen = makeAsync(function*(req, res) {
- res.status(200).send('Random value is: ' + (yield asyncFunc()))
- })
Add Comment
Please, Sign In to add comment