# all-in-throttle-out-queue

> Queue that accept all the inputs and batch the result to output them on a regular interval of time

Latest version **0.0.3** (published 2022-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install all-in-throttle-out-queue
pnpm add all-in-throttle-out-queue
yarn add all-in-throttle-out-queue
bun add all-in-throttle-out-queue
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2022-12-21 |
| First published | 2022-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 15 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Patrick Desjardins |
| Maintainers | mrdesjardins |
| Keywords | node, rate limit, queue, throttle, throttled |

## Links

- npm: https://www.npmjs.com/package/all-in-throttle-out-queue
- Repository: https://github.com/MrDesjardins/all-in-throttle-out-queue
- Homepage: https://github.com/MrDesjardins/all-in-throttle-out-queue#readme
- Issues: https://github.com/MrDesjardins/all-in-throttle-out-queue.git/issues
- npm.io page: https://npm.io/package/all-in-throttle-out-queue

## Dependencies (15)

- [jest](https://npm.io/package/jest.md) ^29.3.1
- [tsup](https://npm.io/package/tsup.md) ^6.5.0
- [eslint](https://npm.io/package/eslint.md) ^8.30.0
- [ts-jest](https://npm.io/package/ts-jest.md) ^29.0.3
- [ts-node](https://npm.io/package/ts-node.md) ^10.9.1
- [benchmark](https://npm.io/package/benchmark.md) ^2.1.4
- [typescript](https://npm.io/package/typescript.md) ^4.9.4
- [eslint-plugin-node](https://npm.io/package/eslint-plugin-node.md) ^11.1.0
- [eslint-plugin-import](https://npm.io/package/eslint-plugin-import.md) ^2.26.0
- [eslint-plugin-promise](https://npm.io/package/eslint-plugin-promise.md) ^6.1.1
- [eslint-config-prettier](https://npm.io/package/eslint-config-prettier.md) ^8.5.0
- [eslint-config-standard](https://npm.io/package/eslint-config-standard.md) ^17.0.0
- [eslint-plugin-prettier](https://npm.io/package/eslint-plugin-prettier.md) ^4.2.1
- [@typescript-eslint/parser](https://npm.io/package/@typescript-eslint/parser.md) ^5.46.1
- [@typescript-eslint/eslint-plugin](https://npm.io/package/@typescript-eslint/eslint-plugin.md) ^5.46.1

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2022-12-21
- 0.0.2 — 2022-12-21
- 0.0.1 — 2022-12-21

## README

[![Build, Test and Coverage](https://github.com/MrDesjardins/all-in-throttle-out-queue/actions/workflows/action.yml/badge.svg?branch=master)](https://github.com/MrDesjardins/all-in-throttle-out-queue/actions/workflows/action.yml)
[![codecov](https://codecov.io/gh/MrDesjardins/all-in-throttle-out-queue/branch/master/graph/badge.svg?token=0HGGX9Z9OW)](https://codecov.io/gh/MrDesjardins/all-in-throttle-out-queue)
[![](https://img.shields.io/badge/Benchmark-%E2%9C%85-brightgreen)](https://mrdesjardins.github.io/all-in-throttle-out-queue/dev/bench/)
![ESNext Target](https://img.shields.io/badge/Target-ESNEXT-brightgreen.svg?style=plastic)
![CommonJs Target](https://img.shields.io/badge/Target-CommonJS-brightgreen?style=plastic)
![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=plastic&logo=typescript&logoColor=white)
[![npm](https://img.shields.io/npm/v/all-in-throttle-out-queue?style=plastic)](https://www.npmjs.com/package/all-in-throttle-out-queue)

# All-in-throttle-out-queue TypeScript

A queue that take all the input it receives and wait a specific time to output the result

![](./readme_assets/queue_npm.drawio.png)

# Use cases?

## Network Calls

Add multiple data in the queue, then after some times take a batch of data to send to a network call

![](./readme_assets/queue_npm2.drawio.png)

## User Interface

For user movements/actions to send 1 payload instead of multiple to avoid traffic and lags but still capturing every piece of data

# How to Use?

Install with NPM:

```sh
npm install --save all-in-throttle-out-queue
```

The project is in TypeScript. The build contains an ESCommon and CommonJS version with `.d.ts`

```typescript
// Create the queue with the type you want to hold. E.g. `number`
const aitoq = new AllInThrottledOutQueue<number>((batch: number[]) => {
  // The function is called after 1000 seconds of the first add
  console.log("Here is the list of number from the last 1000 seconds", batch);
}, 1000);

aitoq.add(1); // Will start the internal timer of 1000 milliseconds (see the second parameter)
aitoq.add(2); // Will be batched in the queue
// After 1000 seconds of the first call, the function is called with the argument [1, 2]
```

# Timer

The timer is not always running. If there is many call to the `add` function, the first time the `AllInThrottledOutQueue` detects that there is no timer and start one. Until the throttleling is completed (function is called) there is always only a single timer. A new timer is only executed if there is another `add` called once there is no timer.

```typescript
// t=0
aitoq.add(1); // Start timer
//t= 100
aitoq.add(2); // Time is still < 1000, same timer (batch)
//t= 1001
//Function called, batch released and back to an empty queue with no timer
//t= 2000
//Still no timer, no need, nothing in the queue
aitoq.add(3); // Start timer
```

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