Skip to content

Commit 7ac13ff

Browse files
committed
Refactor to not use getters but object
1 parent 52e7d94 commit 7ac13ff

4 files changed

Lines changed: 15 additions & 56 deletions

File tree

lib/core/symbols.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,5 @@ module.exports = {
6464
kMaxConcurrentStreams: Symbol('max concurrent streams'),
6565
kNoProxyAgent: Symbol('no proxy agent'),
6666
kHttpProxyAgent: Symbol('http proxy agent'),
67-
kHttpsProxyAgent: Symbol('https proxy agent'),
68-
kStats: Symbol('stats')
67+
kHttpsProxyAgent: Symbol('https proxy agent')
6968
}

lib/dispatcher/client.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ const {
5252
kOnError,
5353
kHTTPContext,
5454
kMaxConcurrentStreams,
55-
kResume,
56-
kStats
55+
kResume
5756
} = require('../core/symbols.js')
5857
const connectH1 = require('./client-h1.js')
5958
const connectH2 = require('./client-h2.js')
@@ -251,8 +250,6 @@ class Client extends DispatcherBase {
251250

252251
this[kResume] = (sync) => resume(this, sync)
253252
this[kOnError] = (err) => onError(this, err)
254-
255-
this[kStats] = new ClientStats(this)
256253
}
257254

258255
get pipelining () {
@@ -265,7 +262,7 @@ class Client extends DispatcherBase {
265262
}
266263

267264
get stats () {
268-
return this[kStats]
265+
return new ClientStats(this)
269266
}
270267

271268
get [kPending] () {

lib/dispatcher/pool-base.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const { PoolStats } = require('../util/stats.js')
44
const DispatcherBase = require('./dispatcher-base')
55
const FixedQueue = require('./fixed-queue')
6-
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch, kStats } = require('../core/symbols')
6+
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch } = require('../core/symbols')
77

88
const kClients = Symbol('clients')
99
const kNeedDrain = Symbol('needDrain')
@@ -66,8 +66,6 @@ class PoolBase extends DispatcherBase {
6666
this[kOnConnectionError] = (origin, targets, err) => {
6767
pool.emit('connectionError', origin, [pool, ...targets], err)
6868
}
69-
70-
this[kStats] = new PoolStats(this)
7169
}
7270

7371
get [kBusy] () {
@@ -107,7 +105,7 @@ class PoolBase extends DispatcherBase {
107105
}
108106

109107
get stats () {
110-
return this[kStats]
108+
return new PoolStats(this)
111109
}
112110

113111
async [kClose] () {

lib/util/stats.js

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,23 @@ const {
99
kQueued
1010
} = require('../core/symbols')
1111

12-
const kPool = Symbol('pool')
13-
const kClient = Symbol('client')
14-
1512
class ClientStats {
1613
constructor (client) {
17-
this[kClient] = client
18-
}
19-
20-
get connected () {
21-
return this[kClient][kConnected]
22-
}
23-
24-
get pending () {
25-
return this[kClient][kPending]
26-
}
27-
28-
get running () {
29-
return this[kClient][kRunning]
30-
}
31-
32-
get size () {
33-
return this[kClient][kSize]
14+
this.connected = client[kConnected]
15+
this.pending = client[kPending]
16+
this.running = client[kRunning]
17+
this.size = client[kSize]
3418
}
3519
}
3620

3721
class PoolStats {
3822
constructor (pool) {
39-
this[kPool] = pool
40-
}
41-
42-
get connected () {
43-
return this[kPool][kConnected]
44-
}
45-
46-
get free () {
47-
return this[kPool][kFree]
48-
}
49-
50-
get pending () {
51-
return this[kPool][kPending]
52-
}
53-
54-
get queued () {
55-
return this[kPool][kQueued]
56-
}
57-
58-
get running () {
59-
return this[kPool][kRunning]
60-
}
61-
62-
get size () {
63-
return this[kPool][kSize]
23+
this.connected = pool[kConnected]
24+
this.free = pool[kFree]
25+
this.pending = pool[kPending]
26+
this.queued = pool[kQueued]
27+
this.running = pool[kRunning]
28+
this.size = pool[kSize]
6429
}
6530
}
6631

0 commit comments

Comments
 (0)