https://github.com/blackglory/extra-pool
🌲 A library that helps you create object/thread/connection pools
https://github.com/blackglory/extra-pool
browser library nodejs npm-package typescript
Last synced: 3 months ago
JSON representation
🌲 A library that helps you create object/thread/connection pools
- Host: GitHub
- URL: https://github.com/blackglory/extra-pool
- Owner: BlackGlory
- License: mit
- Created: 2022-07-25T05:45:26.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-10T18:23:46.000Z (about 3 years ago)
- Last Synced: 2025-06-29T11:52:43.754Z (about 1 year ago)
- Topics: browser, library, nodejs, npm-package, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/extra-pool
- Size: 241 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# extra-pool
A library that helps you create object/thread/connection pools.
## Install
```sh
npm install --save extra-pool
# or
yarn add extra-pool
```
## Usage
```ts
import { Pool } from 'extra-pool'
const dbConnectionPool = new Pool({
create: () => Database.connect(/* ... */)
, destroy: connection => conneciton.close()
, minInstances: 1
, maxInstances: 8
, idleTimeout: 1000 * 60
})
const rows = await dbConnectionPool.use(connection => connection.query(/* ... */))
await dbConnectionPool.destroy()
```
## API
### Pool
```ts
interface IPoolOptions {
create: () => Awaitable
destroy?: (instance: T) => Awaitable
maxInstances?: number
minInstances?: number = 0
idleTimeout?: number = 0
concurrencyPerInstance? = 1
}
class Pool {
readonly capacity: number
readonly size: number
constructor(options: IPoolOptions)
prewarm(targetInstances: number): Promise
use(fn: (instance: T) => Awaitable): Promise
destroy(): Promise
}
```