Skip to content

Latest commit

 

History

History
36 lines (30 loc) · 650 Bytes

prefer-await-to-then.md

File metadata and controls

36 lines (30 loc) · 650 Bytes

Prefer await to then() for reading Promise values (prefer-await-to-then)

Valid

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)
  }
}

Invalid

function example() {
  return myPromise.then(doSomethingSync).then(doSomethingElseAsync)
}

function exampleTwo() {
  return myPromise
    .then(doSomethingSync)
    .then(doSomethingElseAsync)
    .catch(errors)
}