Using Async and Promises in OpenWhisk
Occasionally you may encounter a need to define an action in OpenWhisk where you have to perform a number of steps in a specific order and return the result asynchronously. This is rather simple to achieve in OpenWhisk by using async.series wrapped in a Promise. The following code example shows you how to do this. The key aspects to keep in mind are that in each series function you call the callback and indicate whether or not the current function has succeeded or encountered an error. Once all the functions in the series have been called the last function is called and it is at this point where you handle the promise. In the event an error has occurred somewhere the reject function will get called and if the function calls in the series were successful, then the resolve function will be called.