Skip to content

Instantly share code, notes, and snippets.

@esmevane
Created January 29, 2016 19:13
Show Gist options
  • Save esmevane/31c9f35e81c27799f3b7 to your computer and use it in GitHub Desktop.
Save esmevane/31c9f35e81c27799f3b7 to your computer and use it in GitHub Desktop.
[ ES6 / Babel / ES2016 ]: Adapted version of async / await example from twilio
// Adapted from: https://www.twilio.com/blog/2015/10/asyncawait-the-hero-javascript-deserved.html
//
import Request from 'request'
function getQuote() {
let path = 'http://ron-swanson-quotes.herokuapp.com/quotes'
let request = (resolve, reject) =>
Request(path, (e, r, body) =>
resolve(JSON.parse(body).quote))
let promise = new Promise(request)
return promise
}
async function main() {
var quote = await getQuote()
console.log(quote)
}
main()
console.log('Ron once said,')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment