From reading about async / await, I understood that this construction should simplify the code, save developers from unnecessary callbacks. I ran the following example:
var request = require('request'); var async = require('asyncawait/async'); var await = require('asyncawait/await'); function getQuote() { var quote; return new Promise(function(resolve, reject) { request('http://ron-swanson-quotes.herokuapp.com/v2/quotes', function(error, response, body) { quote = body; resolve(quote); }); }); } var main = async (()=>{ var quote = await(getQuote()); console.log(quote); }); main(); console.log('Ron once said,'); In the console I see the following:
Ron once said, ["Great job, everyone..."] This suggests that main() works after console.log('Ron once said,') .
But what is the point then if one-hell needs to pass a callback to main() to first get the result of the query, and then do something with it?
How to ensure that in this example, first worked main() and then console.log() ?