aggregator
promise aggregator
Install
$ yarn add @zcong/aggregator
# or npm
$ npm i @zcong/aggregator --save
Usage
import { aggregator, withDefaultValue } from '@zcong/aggregator'
// call multi API concurrency
aggregator([
{
fn: () => callImportantAPI(), // will throw when callImportantAPI fail
},
{
fn: () => callOptionalAPI(), // will return fallbackFn when callOptionalAPI fail
fallbackFn: withDefaultValue({ defaultData: 'defaultData' }),
},
{
fn: () => callOptionalAPI2(),
fallbackFn: () => callFallbackAPI(), // not use static value
},
]).then(([importantResp, optionalResp]) => {})
License
MIT © zcong1993