How to use async/await without further Korbakov?

From reading about async/await, I realized that this design should simplify your code, freeing developers from unnecessary Korbakov. I ran this:

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('', function(error, response, body) {
 quote = body;

var main = async (()=>{
 var quote = await(getQuote());


console.log('Ron once said,');

In the console I see the following:

Ron once said,
["Great job, everyone..."]

This says that main() is triggered after console.log('Ron once said,').

But what is the point then if one hell you need to pass callback in main() to first get the query result, and then something to do with it?

How to achieve that in this example, first load main() and then console.log()?
July 9th 19 at 10:20
2 answers
July 9th 19 at 10:22
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,');
July 9th 19 at 10:24
You don't need to specify async if you want to first main volunteered.
Without async I get the following error:
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
You want the javascript worked in sync, but async/await doing everything exactly the opposite. - willow.Hand commented on July 9th 19 at 10:30
: I think you are right. I found the answer, you need to main put await - tracey commented on July 9th 19 at 10:33
Yes, you are right - willow.Hand commented on July 9th 19 at 10:36
: Please show how to solved the problem. If you put the await keyword before main(), it gives an error. - Peyton44 commented on July 9th 19 at 10:39
: it gives an error because you need babel, or wrap everything in IIFE-expression, answered the question with a code example - tracey commented on July 9th 19 at 10:42

Find more questions by tags JavaScript