开发者社区> 镜像站> NPM> awaitable-pool
awaitable-pool
Object pool with an async checkout function.
Last updated 8 months ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install awaitable-pool 
SYNC missed versions from official npm registry.

awaitable-pool

Object pool with an async checkout function.

Example

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.

LICENSE

MIT

Current Tags

  • 0.2.1                                ...           latest (8 months ago)

3 Versions

  • 0.2.1                                ...           8 months ago
  • 0.2.0                                ...           8 months ago
  • 0.1.0                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)
Dependents (0)
None