In considering this comment I discovered one can use .reduce() to return promises in sequence (which I also thought cool enough to share):
functionrunPromiseInSequence(arr,input){returnarr.reduce((promiseChain,currentFunction)=>promiseChain.then(currentFunction),Promise.resolve(input))}// promise function 1functionp1(a){returnnewPromise((resolve,reject)=>{resolve(a*5)})}// promise function 2functionp2(a){returnnewPromise((resolve,reject)=>{resolve(a*2)})}// function 3 - will be wrapped in a resolved promise by .then()functionf3(a){returna*3}// promise function 4functionp4(a){returnnewPromise((resolve,reject)=>{resolve(a*4)})}constpromiseArr=[p1,p2,f3,p4]runPromiseInSequence(promiseArr,10).then(console.log)// 1200
Good thoughts, that's for leading me to that find.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In considering this comment I discovered one can use .reduce() to return promises in sequence (which I also thought cool enough to share):
Good thoughts, that's for leading me to that find.