async function example() {
let val = await myPromise()
val = doSomethingSync(val)
return doSomethingElseAsync(val)
}
async function exampleTwo() {
try {
let val = await myPromise()
val = doSomethingSync(val)
return await doSomethingElseAsync(val)
} catch (err) {
errors(err)
}
}
function example() {
return myPromise.then(doSomethingSync).then(doSomethingElseAsync)
}
function exampleTwo() {
return myPromise
.then(doSomethingSync)
.then(doSomethingElseAsync)
.catch(errors)
}
function exampleThree() {
return myPromise.catch(errors)
}
function exampleFour() {
return myPromise.finally(cleanup)
}
Normally, this rule allows then
or catch
following an await
(or yield
)
expression. Setting this option to true
will err on such cases:
This will fail with the strict
option:
async function hi() {
await thing().then()
}