Guest User

Untitled

a guest
Nov 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. const makeAsync = require('es6-async')
  2.  
  3. const timeout = (milliseconds) => new Promise(resolve => setTimeout(resolve, milliseconds))
  4. const random = () => Promise.resolve(Math.random())
  5.  
  6. const asyncFunc = makeAsync(function* () {
  7. yield timeout(1000)
  8. return yield random()
  9. })
  10.  
  11. module.exports.randomGen = makeAsync(function*(req, res) {
  12. res.status(200).send('Random value is: ' + (yield asyncFunc()))
  13. })
Add Comment
Please, Sign In to add comment