Skip to content

Files

Latest commit

 

History

History
40 lines (28 loc) · 672 Bytes

no-nesting.md

File metadata and controls

40 lines (28 loc) · 672 Bytes

Pattern: Use of nesting promises

Issue: -

Description

Avoid nested then() or catch() statements.

Example of correct code:

myPromise
  .then(doSomething)
  .then(doSomethingElse)
  .catch(errors)

Example of incorrect code:

myPromise.then(val => {
  doSomething(val).then(doSomethingElse)
})

myPromise.then(val => {
  doSomething(val).catch(errors)
})

myPromise.catch(err => {
  doSomething(err).then(doSomethingElse)
})

myPromise.catch(err => {
  doSomething(err).catch(errors)
})

Further Reading