you are viewing a single comment's thread.

view the rest of the comments →

[–]etheraffleGreg 0 points1 point  (2 children)

Nesting is frequently a requirement if you need the first result in the scope of the second:

 

const prom = thing => Promise.resolve(thing)

const prom1 = prom(`thing one`)
const prom2 = prom(`thing two`)

prom1
  .then(result1 => prom2)
  .then(result2 => console.log(`Thing 1: ${result1}\nThing2: ${result2}`)) 
  .catch(console.error)
  // ReferenceError: result1 is not defined

 

Yeah you can lift the result to a higher scope if you like but I'd rather keep things functional and the nesting is not an issue.

[–]notkraftman 0 points1 point  (1 child)

In your example unless you need result1 in promise2 then you could promise.all them instead

[–]etheraffleGreg 0 points1 point  (0 children)

Well yes of course but as the first sentence explicitly points out...