Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): add missing pool stats #1573

Merged
merged 2 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion test/types/pool.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Duplex, Readable, Writable } from 'stream'
import { expectAssignable } from 'tsd'
import { expectAssignable, expectType } from 'tsd'
import { Dispatcher, Pool, Client } from '../..'
import { URL } from 'url'

Expand All @@ -16,6 +16,7 @@ expectAssignable<Pool>(new Pool('', { connections: 1 }))
// properties
expectAssignable<boolean>(pool.closed)
expectAssignable<boolean>(pool.destroyed)
expectAssignable<Pool.PoolStats>(pool.stats)

// request
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: '', path: '', method: 'GET' }))
Expand Down Expand Up @@ -100,4 +101,12 @@ expectAssignable<Pool>(new Pool('', { connections: 1 }))
expectAssignable<void>(pool.destroy(() => {}))
expectAssignable<void>(pool.destroy(new Error(), () => {}))
expectAssignable<void>(pool.destroy(null, () => {}))

// stats
expectType<number>(pool.stats.connected)
expectType<number>(pool.stats.free)
expectType<number>(pool.stats.pending)
expectType<number>(pool.stats.queued)
expectType<number>(pool.stats.running)
expectType<number>(pool.stats.size)
}
19 changes: 19 additions & 0 deletions types/pool-stats.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Pool = require("./pool")

export = PoolStats

declare class PoolStats {
constructor(pool: Pool);
/** Number of open socket connections in this pool. */
connected: number;
/** Number of open socket connections in this pool that do not have an active request. */
free: number;
/** Number of pending requests across all clients in this pool. */
pending: number;
/** Number of queued requests across all clients in this pool. */
queued: number;
/** Number of currently active requests across all clients in this pool. */
running: number;
/** Number of active, pending, or queued requests across all clients in this pool. */
size: number;
}
4 changes: 4 additions & 0 deletions types/pool.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Client = require('./client')
import Dispatcher = require('./dispatcher')
import TPoolStats = require('./pool-stats')
import { URL } from 'url'

export = Pool
Expand All @@ -10,9 +11,12 @@ declare class Pool extends Dispatcher {
closed: boolean;
/** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */
destroyed: boolean;
/** Aggregate stats for a Pool. */
readonly stats: TPoolStats;
}

declare namespace Pool {
export type PoolStats = TPoolStats;
export interface Options extends Client.Options {
/** Default: `(origin, opts) => new Client(origin, opts)`. */
factory?(origin: URL, opts: object): Dispatcher;
Expand Down