https://github.com/thundernet8/node-socket-pool
Socket connection pool for Node
https://github.com/thundernet8/node-socket-pool
nodejs pool socket
Last synced: about 1 year ago
JSON representation
Socket connection pool for Node
- Host: GitHub
- URL: https://github.com/thundernet8/node-socket-pool
- Owner: thundernet8
- License: mit
- Created: 2017-11-15T15:22:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-22T02:42:13.000Z (over 8 years ago)
- Last Synced: 2025-04-22T05:19:10.866Z (about 1 year ago)
- Topics: nodejs, pool, socket
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Node-Socket-Pool [](https://travis-ci.org/thundernet8/Node-Socket-Pool)
Socket connection pool for Node
## Install
```
npm install node-socket-pool
```
or
```
yarn add node-socket-pool
```
## Usage
### Get a client
```typescript
import SocketPool from "node-socket-pool";
const pool = new SocketPool({
host: "127.0.0.1",
port: 3000,
maxActive: 5,
maxIdle: 2,
maxIdleTime: 30000,
maxWait: 10000
});
// in async function
const socketClient = await pool.getResource();
// or promise
pool
.getResource()
.then(client => {})
.catch(err => {
// handle err
});
```
### Options
```typescript
host: string;
port: number;
// 最多维持连接数
maxActive?: number;
// 最多保留空闲连接数
maxIdle?: number;
// Socket连接最长空闲时间(毫秒)(超过时间后将返回资源池)
maxIdleTime?: number;
// pool中没有资源返回时,最大等待时间(毫秒)
maxWait?: number;
```
### Release
```typescript
client.release();
```
or
```typescript
pool.returnResource(client);
```
client will auto return to idle resource pool if no data transportation for a
time up to maxIdleTime option
### License
Node-socket-pool is freely distributable under the terms of the
[MIT license](https://github.com/thundernet8/Node-Socket-Pool/blob/master/LICENSE).
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fthundernet8%2FNode-Socket-Pool?ref=badge_large)