# pacedcaller

> Library to make paced asynchronous calls and report progress

Latest version **0.2.1** (published 2019-04-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install pacedcaller
pnpm add pacedcaller
yarn add pacedcaller
bun add pacedcaller
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2019-04-12 |
| First published | 2019-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 23 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | manoj.clsd.kumar@gmail.com |
| Maintainers | manojclsdkumar |
| Keywords | async-loop, timed-loop |

## Links

- npm: https://www.npmjs.com/package/pacedcaller
- npm.io page: https://npm.io/package/pacedcaller

## Dependencies (2)

- [chai](https://npm.io/package/chai.md) ^4.2.0
- [rxjs](https://npm.io/package/rxjs.md) ^6.4.0

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2019-04-12
- 0.2.0 — 2019-04-12
- 0.1.7 — 2019-04-12
- 0.1.5 — 2019-04-12
- 0.1.4 — 2019-04-12
- 0.1.3 — 2019-04-12
- 0.1.2 — 2019-04-12
- 0.1.1 — 2019-04-12
- 0.1.0 — 2019-04-12
- 0.0.3 — 2019-04-11
- 0.0.2 — 2019-04-11
- 0.0.1 — 2019-04-11

## README

# Paced Caller

**What is this?**


Library designed to allow async calls to a function
to be made over time in a controlled manner.

 

ie -> *I want to call a function for each element in a loop, each call should be spaced 2000 milliseconds apart.*

**Why would I want to do this?**

Say you want to hit an API with a rate limit, and need requests to be spaced X time apart.

Say you want to loop through an array, and execute a function, but each iteration must
only occur after the last iteration.


**How can I use this?**

Import the library with 

`npm install pacedcaller`

The library is designed with typescript in mind so:
```javascript 
import {pacedCall} from 'pacedcaller'
```
Declare a paced called:
```javascript 
let calls = new pacedCall(iterationData, timeDelay, actions, fragmentationSize);`
```
*iterationData* - Array of any type data, of any size.

*timeDelay* - Time in milliseconds between each loop.

*actions* - Function to repeat on each element, takes in an ARRAY of elements (fragment) and returns an array of results.

*fragmentationSize* - The size of a fragment.

**Woah Hey.. What is a fragment?**

The library is designed to 'batch' runs. For instance imagine hitting an api that accepts 200 locations at a time in an array. But you have an array of 16k sites. This function will 'batch' the 16k array into 'blocks' of 200. For this reason you 'action' function accepts an ARRAY of data, not a single point of data.

It's perfectly valid to have a single point of data in an array though.

For example, You have an set of lat/lng points [{lat:x,lng:y}, {lat:x,lng:y} ...etc x 16,000]

You have an API that accepts 200 points at a time.

Simply instantiate a pacedCall class:

```javascript 
const latlngArray = [...{'lat':x,'lng':y}]
```

```javascript
let calls = new pacedCall(
  [...latLngArray],
  2000,
  (latlngSubset) => {
    makeAPICall(latlngSubset);
  },
  200
);

```


The result will be like:
```javascript
[
  { request: { lat: x, lng: x }, result: result },
  { request: { lat: x, lng: x }, result: result },
  { request: { lat: x, lng: x }, result: result },
  { request: { lat: x, lng: x }, result: result }... x 16,000
];

```


TODO:
- Allow actions to take in a single value not in an array.
- Allow an option to execute each loop directly after the previous loop finishes, as opposed to requiring a time between each iteration.

---
_Source: https://npm.io/package/pacedcaller · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
