Oracle Magazine, Jan/Feb 2018
Database Developer OPEN SOURCE ORACLE MAGAZINE JANUARY FEBRUARY 2018 67 logNumbers Running this script in Node js you should see three numbers printed to the console every two seconds There are no third party libraries and no complicated promise chains just a simple loop Loops work again PARALLEL EXECUTION Clearly async functions make it easy to do sequential flows and use standard JavaScript constructs with asynchronous operations But what about parallel flows This is where Promise all and Promise race come in handy Because they both return promises await can work with them as with any other promise based API Heres an example that uses Promise all to get three random numbers in parallel function getRandomNumber return new Promise function resolve reject setTimeout function const randomValue Math random const error randomValue 8 true false if error reject new Error Ooops something broke else resolve randomValue 2000
You must have JavaScript enabled to view digital editions.