0.2.2 • Published 6 years ago

node-socket-pool v0.2.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Node-Socket-Pool Build Status

Socket connection pool for Node

Install

npm install node-socket-pool

or

yarn add node-socket-pool

Usage

Get a client

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

host: string;
port: number;
// 最多维持连接数
maxActive?: number;
// 最多保留空闲连接数
maxIdle?: number;
// Socket连接最长空闲时间(毫秒)(超过时间后将返回资源池)
maxIdleTime?: number;
// pool中没有资源返回时,最大等待时间(毫秒)
maxWait?: number;

Release

client.release();

or

pool.returnResource(client);

client will auto return to idle resource pool if no data transportation for a time up to maxIdleTime option

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.5

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago