Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/awaitable-pool
Object pool with an async checkout function.
https://github.com/thlorenz/awaitable-pool
Last synced: 13 days ago
JSON representation
Object pool with an async checkout function.
- Host: GitHub
- URL: https://github.com/thlorenz/awaitable-pool
- Owner: thlorenz
- License: mit
- Created: 2020-04-14T20:13:25.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-15T16:51:37.000Z (almost 5 years ago)
- Last Synced: 2024-12-10T08:26:52.347Z (about 1 month ago)
- Language: TypeScript
- Size: 8.79 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# awaitable-pool [![](https://github.com/thlorenz/awaitable-pool/workflows/Node%20CI/badge.svg?branch=master)](https://github.com/thlorenz/awaitable-pool/actions)
Object pool with an async checkout function.
## Example
```js
const { AwaitablePool } = require('awaitable-pool')let count = 0
const poolSize = 2
const createObject = () => ({
id: (++count).toString(),
})const pool = new AwaitablePool(createObject, poolSize)
;(async () => {
const item1 = await pool.checkout()
console.log('checked out %s', item1.id)
const item2 = await pool.checkout()
console.log('checked out %s', item2.id)console.log('checking out another item')
pool.checkout().then((item) => console.log('checked out %s', item.id))console.log('checking in 1')
pool.checkin(item1)
})()
``````
checked out 1
checked out 2
checking out another item
checking in 1
checked out 1
```## Installation
npm install awaitable-pool
## Alternatives
This library is small and thus also only serves a small spectrum of use cases.
If you want a more complete implementation have a look at either of the following.- [tarn](https://github.com/Vincit/tarn.js)
## LICENSE
MIT