Last active
November 15, 2017 23:06
-
-
Save hallski/d86e34853acb6e288393b3d03232d21f to your computer and use it in GitHub Desktop.
Google Cloud Function using es6-async
This file contains hidden or 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 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