Oracle Magazine, September/October 2017
Database Developer OPEN SOURCE ORACLE MAGAZINE SEPTEMBER OCTOBER 2017 54 else console log Connection closed getConnection Copy this code to a new file name it named functions js and run the script as before You should get the same output as with the previous version of the code anon functions js In the named functions js code Ive declared named functions for each operation and then kicked off the sequence of functions at the bottom of the code by invoking the first of the functions to be executed getConnection With this technique its relatively easy to organize sequential asynchronous operations More complex operations such as iterating an array asynchronously or doing multiple asynchronous tasks in parallel would require something more You could write your own library but why reinvent the wheel when you can just use Async one of the most popular Node js libraries ever LEVERAGING THE ASYNC MODULE You can think of Async as a module that extends the Node js style callback pattern Async is not included with Node js so it must be installed with a command such as npm install async With Async installed you can require the library and take advantage of its 70 plus methods for various asynchronous processing situations
You must have JavaScript enabled to view digital editions.