Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zcong1993/aggregator
promise aggregator
https://github.com/zcong1993/aggregator
Last synced: about 23 hours 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 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-19T05:58:56.000Z (about 3 years ago)
- Last Synced: 2023-02-28T14:37:10.410Z (over 1 year ago)
- Language: TypeScript
- Size: 942 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# aggregator
[![NPM version](https://img.shields.io/npm/v/@zcong/aggregator.svg?style=flat)](https://npmjs.com/package/@zcong/aggregator) [![NPM downloads](https://img.shields.io/npm/dm/@zcong/aggregator.svg?style=flat)](https://npmjs.com/package/@zcong/aggregator) [![JS Test](https://github.com/zcong1993/aggregator/actions/workflows/js-test.yml/badge.svg)](https://github.com/zcong1993/aggregator/actions/workflows/js-test.yml) [![codecov](https://codecov.io/gh/zcong1993/aggregator/branch/master/graph/badge.svg)](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