Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

awaitable-pool

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

awaitable-pool

Object pool with an async checkout function.

latest
Source
npmnpm
Version
0.2.1
Version published
Maintainers
1
Created
Source

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.

  • tarn

LICENSE

MIT

Keywords

pool

FAQs

Package last updated on 15 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts