https://github.com/zcong1993/aggregator
promise aggregator
https://github.com/zcong1993/aggregator
Last synced: 8 months ago
JSON representation
promise aggregator
- Host: GitHub
- URL: https://github.com/zcong1993/aggregator
- Owner: zcong1993
- License: mit
- Created: 2020-05-23T17:15:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-19T05:58:56.000Z (almost 4 years ago)
- Last Synced: 2025-02-18T05:48:22.500Z (8 months ago)
- Language: TypeScript
- Size: 942 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# aggregator
[](https://npmjs.com/package/@zcong/aggregator) [](https://npmjs.com/package/@zcong/aggregator) [](https://github.com/zcong1993/aggregator/actions/workflows/js-test.yml) [](https://codecov.io/gh/zcong1993/aggregator)
> promise aggregator
## Install
```bash
$ yarn add @zcong/aggregator
# or npm
$ npm i @zcong/aggregator --save
```## Usage
```ts
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