Interface ConnectionPoolOptions<T>

Helper class to manage persistent connections like websockets.

interface ConnectionPoolOptions<T> {
    closeCb?: ((conn) => Promise<void>);
    connectCb: ((timeout) => Promise<T>);
    connectTimeout?: number;
    markRefreshedOnGet?: boolean;
    maxSessionDuration?: number;
}

Type Parameters

  • T

Properties

closeCb?: ((conn) => Promise<void>)

Optional async callback to close connections.

Type declaration

    • (conn): Promise<void>
    • Parameters

      • conn: T

        The connection to close

      Returns Promise<void>

connectCb: ((timeout) => Promise<T>)

Async callback to create new connections.

Type declaration

    • (timeout): Promise<T>
    • Parameters

      • timeout: number

        Connection timeout in milliseconds

      Returns Promise<T>

Returns

A new connection object

connectTimeout?: number

Default connection timeout in milliseconds. Defaults to 10000 (10 seconds).

markRefreshedOnGet?: boolean

If true, the session will be marked as fresh when get() is called. Only used when maxSessionDuration is set.

maxSessionDuration?: number

Maximum duration in milliseconds before forcing reconnection. If not set, connections will never expire based on duration.