node-beanstalk
Version:
The most comprehensive beanstalk client for nodejs
54 lines (53 loc) • 1.83 kB
TypeScript
import { IPoolCtorOptions } from './types';
import { PoolClient } from './PoolClient';
export declare type PoolState = 'live' | 'disconnected' | 'disconnecting';
export declare class Pool {
private readonly _opt;
private readonly _clients;
private readonly _idleClients;
private readonly _pendingQueue;
private _state;
constructor(options?: IPoolCtorOptions);
/**
* Total capacity of the pool.
*/
get capacity(): number;
/**
* Amount of clients which are not reserved and currently idle in the pool.
*/
get idleCount(): number;
/**
* Total amount of queued client requests when all clients are reserved. It is helpful to monitor
* this number to see if you need to adjust the size of the pool.
*/
get waitingCount(): number;
/**
* Current pool state.
*/
getState(): PoolState;
/**
* Reserve a client from the pool.
*
* If the pool is full and all clients are currently reserved, this will wait in a FIFO queue
* until a client becomes available by it being released back to the pool.
*
* If there are idle clients in the pool it will be returned.
*
* If the pool is not full a new client will be created and connected.
*/
connect(): Promise<PoolClient>;
/**
* Disconnect all clients from server after all pending requests performed.
* All currently reserved clients will not be returned to the pool and ended in-place after all
* pending requests performed.
*
* If {force} set to truthy value - clients pending requests will not be awaited.
*/
disconnect(force?: boolean): Promise<void>;
/**
* Restore pool from disconnected state.
*/
restore(): void;
private createPendingPromise;
private handleClientRelease;
}