0

With the following example using async/await, I would to convert it in explicit Promise:

conts promises = [promise1, promise2, promise3, promise4]

async function (message) 
{
  let transformedMessage = message
  for(let p of promises) 
  {
      transformedMessage = await p(transformedMessage)
  }
  return transformedMessage
}

I didn't find any collection which permits to reuse the resolve value as argument of the following iteration.

Miracle
  • 387
  • 5
  • 31
PPCM
  • 157
  • 11
  • What exactly is your question? If `p` is actually a promise, then `await p(transformedMessage)` does not make any sense because you don't execute promises (they are objects, not functions). If `p` is a function that returns a promise, then that could work, but your code nomenclature is really messed up. – jfriend00 Mar 26 '18 at 22:10
  • Also, `for (let p in promises)` should be `for (let p of promises)` to iterate the array. Still not sure what you're actually trying to accomplish here. – jfriend00 Mar 26 '18 at 22:11
  • Your are right, a typing error occured, it should be a for...of The goal is to play a sequence of promises and reuse the result in the call of the next promise – PPCM Mar 27 '18 at 05:37
  • Maybe this is related: [How to synchronize a sequence of promises](https://stackoverflow.com/questions/29880715/how-to-synchronize-a-sequence-of-promises/29906506#29906506) – jfriend00 Mar 27 '18 at 05:48
  • Great, I didn't really understood how to use Promise.reduce, but now it is more clear and it does what I need. Thanks! – PPCM Mar 27 '18 at 08:05

0 Answers0