# wrr-pool

> Weighted Round Robin Resource pool

Latest version **1.1.4** (published 2018-11-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install wrr-pool
pnpm add wrr-pool
yarn add wrr-pool
bun add wrr-pool
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2018-11-29 |
| First published | 2016-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 62.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Oleksiy Krivoshey |
| Maintainers | oleksiyk |
| Keywords | weighted, roundrobin |

## Links

- npm: https://www.npmjs.com/package/wrr-pool
- Repository: https://github.com/oleksiyk/wrr-pool
- Homepage: http://github.com/oleksiyk/wrr-pool
- Issues: https://github.com/oleksiyk/wrr-pool/issues
- npm.io page: https://npm.io/package/wrr-pool

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11

## Recent versions

- 1.1.4 (latest) — 2018-11-29
- 1.1.3 — 2016-02-06
- 1.1.2 — 2016-02-05
- 1.1.1 — 2016-02-04
- 1.1.0 — 2016-02-04
- 1.0.5 — 2016-02-04
- 1.0.4 — 2016-01-30
- 1.0.3 — 2016-01-28
- 1.0.2 — 2016-01-28
- 1.0.1 — 2016-01-28
- 1.0.0 — 2016-01-28
- 0.0.2 — 2016-01-28
- 0.0.1 — 2016-01-28

## README

[![Build Status](https://travis-ci.org/oleksiyk/wrr-pool.svg)](https://travis-ci.org/oleksiyk/wrr-pool)
[![Test Coverage](https://codeclimate.com/github/oleksiyk/wrr-pool/badges/coverage.svg)](https://codeclimate.com/github/oleksiyk/wrr-pool/coverage)
[![Dependencies](https://david-dm.org/oleksiyk/wrr-pool.svg)](https://david-dm.org/oleksiyk/wrr-pool)
[![DevDependencies](https://david-dm.org/oleksiyk/wrr-pool/dev-status.svg)](https://david-dm.org/oleksiyk/wrr-pool#info=devDependencies)

# WRRPool

WRRPool is a Weighted Round Robin resource pool

## Using

```
npm install wrr-pool
```

#### Basic usage

```javascript
var WRRPool = require('wrr-pool');

var pool = new WRRPool();

pool.add('A', 4); // pool.add({ host: '10.0.1.10', port: 8087}, 4)
pool.add('B', 3); // pool.add({ host: '10.0.1.11', port: 8087}, 3)
pool.add('C', 2); // pool.add({ host: '10.0.1.12', port: 8087}, 2)

pool.next(); // A
pool.next(); // A
pool.next(); // B
pool.next(); // A
pool.next(); // B
pool.next(); // C
pool.next(); // A
pool.next(); // B
pool.next(); // C
```

#### Get resource and its weight

```javascript
var pool = new WRRPool();

pool.add({ id: 1 }, 4);
pool.add({ id: 2 }, 3);
pool.add({ id: 3 }, 2);

pool.get({ id: 2 }); // => { value: { id: 2 }, weight: 3 }
```

```javascript
var pool = new WRRPool();

pool.add({ id: 1 }, 4);
pool.add({ id: 2 }, 3);
pool.add({ id: 3 }, 2);

pool.get(function (v){ return v.id === 2; }); // => { value: { id: 2 }, weight: 3 }
```

#### Update resource value and/or weight

```javascript
var pool = new WRRPool();

pool.add('A', 4);
pool.add('B', 3);
pool.add('C', 2);

// update value to 'B1' and weight to 4
pool.update(function (v) { return v === 'B';}, 'B1', 4); // => returns index of updated element or undefined if not found
```

#### Remove resource from pool

```javascript
var pool = new WRRPool();

pool.add('A', 4);
pool.add('B', 3);
pool.add('C', 2);

pool.remove(function (v) { return v === 'C';});  // => returns index of removed element or undefined if not found
```

## License
MIT

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