简体   繁体   中英

Should a function remain async when applying 'no-return-await'?

If using return await is unnecessary should the function remain async ?

Using return await inside an async function keeps the current function in the call stack until the Promise that is being awaited has resolved, at the cost of an extra microtask before resolving the outer Promise

https://eslint.org/docs/rules/no-return-await

Example 1

async function foo() {
   return await bar();
}

Example 2

async function foo() {
    return bar();
}

Example 3

function foo() {
    return bar();
}

Bar

async function bar() {
    const data = await externalCall();
    const result = anotherFunction(data);
    return result;
}

If the first example becomes the second example shouldn't it actually become the third example?

是的,如果函数不返回 await,则使用 async 毫无意义。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM