async-wrap
Library with wrapper functions for async function (or functions, that return Promises)
Install
npm install async-wrap
Usage
var asw = asw
or
var coalesce =
Overview
Functions
coalesce
Accepts two parameters:
- elements {Array}: List of elements that should be passed to the callback
- callback {function}: Async callback function (promise) that accepts an element as parameter
Use coalesce to execute a async function again, when it fails, with the next element in the elements list. E.g. you have multiple instances of a service, and want to retry the request with the next service instance if you can't connect to the first service.
Example:
Interactive example on runkit
{ var urls = // Returns array return { return }}
Same using Promise:
{ var urls = // Returns array return { return { } }}
With multiple parameters:
{ var urls = // Returns array return { return }}