May I ask why an async/await, await of es7 can sometimes be omitted?

Test Code:


async function fun1(){
    return fun2();//  await await
}
async function fun2(){
    return fun3();//  await await
}

async function fun3(){
    return new Promise(resolve=>{
        console.log("fun3");
        resolve("fufff 3 ret");
    })
}

async function testfun1(){
    const ret = await fun1();
    console.log(ret);
}
testfun1()

the output of fun1 fun2 plus await is the same.

fun3
fufff 3 ret

Why on earth is this?

Mar.13,2021

  1. first, awati should be followed by Promise instance.
  2. secondly, the async function returns an instance of Promise .

specific to the example of the landlord, fun1 , fun2 the previous async is redundant, because fun1 () = > fun2 () = > fun3 () has returned the Promise instance.

can be changed to the following code.

function bar () {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve('bar');
        }, 1000);
    });
}

async function foo () {
    let ret1 = bar();
    let ret2 = await bar();
    console.log(ret1); // Promise { 'bar' }
    console.log(ret2); // bar
}

foo();
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c197-2ba64.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c197-2ba64.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?