Skip to content

Instantly share code, notes, and snippets.

@hallski
Last active November 15, 2017 23:06
Show Gist options
  • Save hallski/d86e34853acb6e288393b3d03232d21f to your computer and use it in GitHub Desktop.
Save hallski/d86e34853acb6e288393b3d03232d21f to your computer and use it in GitHub Desktop.
Google Cloud Function using es6-async
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()))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment