await
operator should be used at async function call when the resolved value is needed
- MISSING_AWAIT
- Error
- Medium
- es8
This rule applies when the await
operator appears to be missing at an async function call.
The return value of an async function is always a Promise
object, and the resolved value can be obtained by using await
operator.
If the return value of an async function is used in a context inappropriate for a Promise
object, it is likely that the resolved value is intended, but the await
operator is mistakenly omitted.
Noncompliant Code Example
View with compliant examples side by sideasync function fetch(url) {
return doFetch(url);
}
async function getInfo() {
const result = fetch('/info'); // MISSING_AWAIT alarm
if (result.status === 200) {
return result.text();
}
throw new Error('Bad response');
}
Compliant Code Example
View with noncompliant examples side by sideasync function fetch(url) {
return doFetch(url);
}
async function getInfo() {
const result = await fetch('/info');
if (result.status === 200) {
return result.text();
}
throw new Error('Bad response');
}
Version
This rule was introduced in DeepScan 1.31.0.