# objects-pool

> Pool for any objects. Prefer use this for connection pools (MySQL, PostresSQL, etc.)

Latest version **1.0.0** (published 2017-12-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install objects-pool
pnpm add objects-pool
yarn add objects-pool
bun add objects-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.0.0 |
| Published | 2017-12-22 |
| First published | 2017-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Barinov Anton |
| Maintainers | antonbarinov |
| Keywords | pool |

## Links

- npm: https://www.npmjs.com/package/objects-pool
- Repository: https://github.com/antonbarinov/ObjectsPool
- Issues: https://github.com/antonbarinov/ObjectsPool/issues
- npm.io page: https://npm.io/package/objects-pool

## Recent versions

- 1.0.0 (latest) — 2017-12-22

## README

# ObjectsPool
Pool for any objects. Prefer use this for connection pools (MySQL, PostresSQL, etc.)

## Install
```
npm i objects-pool
```

## Exmaple

```
const pool = new ObjectsPool();

async function sleep(seconds = 1) {
    return new Promise(resolve => {
        setTimeout(() => {
            resolve(true);
        }, seconds * 1000);
    });
}

pool.put({a: 1}); // put some object in our pool
pool.put({a: 2}); // put some object in our pool
pool.put({a: 3}); // put some object in our pool

async function work(time) {
    const obj = await pool.get(); // get from pool
    await sleep(time);
    console.log(obj);
    pool.put(obj); // put it back to our pool
}

for (let i = 1; i <= 10; i++) {
    if (i <= 2) {
        work(i);
    } else {
        work(0);
    }
}
```

Output:
```
{ a: 3 }
{ a: 3 }
{ a: 3 }
{ a: 3 }
{ a: 3 }
{ a: 3 }
{ a: 3 }
{ a: 3 }
{ a: 1 }
{ a: 2 }
```

## API
- .put(object) - Put `object` to pool.
- .get() - Get object that not busy right now. If all objects busy it will be wait until some one has been released (putted back to the pool).

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