Created
January 29, 2016 19:13
-
-
Save esmevane/31c9f35e81c27799f3b7 to your computer and use it in GitHub Desktop.
[ ES6 / Babel / ES2016 ]: Adapted version of async / await example from twilio
This file contains 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
// 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