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,');
Ron once said,
["Great job, everyone..."]
let getData = () => {
return new Promise(function(resolve, reject) {
setTimeout(() => {
resolve('Great job, everyone...');
}, 500);
});
};
(async () => {
let main = async ()=> {
console.log(await getData());
};
the await main();
console.log('Ron once said,');
})();
Find more questions by tags JavaScript
the await functions yield functions and value-returning suspendable functions may only be called from inside a suspendable function.
Please give a working example? - tracey commented on July 9th 19 at 10:27