Skip to content

Instantly share code, notes, and snippets.

@Gaafar
Created March 16, 2017 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gaafar/8d8767915d4bf2225ee6f844fc525b47 to your computer and use it in GitHub Desktop.
Save Gaafar/8d8767915d4bf2225ee6f844fc525b47 to your computer and use it in GitHub Desktop.
const makeRequest = () => {
return promise1()
.then(value1 => {
// do something
return promise2(value1)
.then(value2 => {
// do something
return promise3(value1, value2)
})
})
}
@Sufiane
Copy link

Sufiane commented Jul 12, 2017

You could do something like this too:

const makeRequest = () => {
    let value1

   return promise1()
         .then(_value1 => {
              value1 = _value1
              
              return promise2(value1)
         })
         .then(value2 => {
              return promise3(value1, value2)
         })
}

It keep everything on the same level :)

@geritol
Copy link

geritol commented Jan 24, 2018

+1 was also going to post the same!

@optimistanoop
Copy link

+1 , Main example could have reduced nesting to look better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment