Skip to content

Commit

Permalink
fix: rename destroyTimeout option
Browse files Browse the repository at this point in the history
Since the connections are being closed and not destroyed after the
timeout, I thought the name was misleading.
  • Loading branch information
dnlup committed Oct 28, 2020
1 parent fff2444 commit 7d1e61e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { Pool } = require('undici')

const {
kHostsMap,
kDestroyTimeout,
kCloseTimeout,
kMaxHosts,
kDefaultConnectionOptions,
kSetupConnection,
Expand All @@ -26,20 +26,20 @@ function onTimeout (key, pool, client) {

class Agent11 {
constructor ({
destroyTimeout = 6e4,
closeTimeout = 6e4,
maxHosts = Infinity,
connectionOptions = {}
} = {}) {
if (typeof destroyTimeout !== 'number' || destroyTimeout <= 0) {
if (typeof closeTimeout !== 'number' || closeTimeout <= 0) {
throw new Error(
'destroyTimeout must be a number > 0'
'closeTimeout must be a number > 0'
)
}
if (typeof maxHosts !== 'number' || maxHosts <= 0) {
throw new Error('maxHosts must be a number > 0')
}
this[kHostsMap] = new Map()
this[kDestroyTimeout] = destroyTimeout
this[kCloseTimeout] = closeTimeout
this[kMaxHosts] = maxHosts
this[kDefaultConnectionOptions] = connectionOptions
this[kTimersMap] = new Map()
Expand All @@ -63,7 +63,7 @@ class Agent11 {
this[kHostsMap].set(key, pool)
this[kTimersMap].set(
pool,
setTimeout(onTimeout, this[kDestroyTimeout], key, pool, this)
setTimeout(onTimeout, this[kCloseTimeout], key, pool, this)
)
}

Expand Down
2 changes: 1 addition & 1 deletion symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
kHostsMap: Symbol('kHostsMap'),
kDestroyTimeout: Symbol('kDestroyTimeout'),
kCloseTimeout: Symbol('kDestroyTimeout'),
kMaxHosts: Symbol('kMaxHosts'),
kDefaultConnectionOptions: Symbol('kDefaultConnectionOptions'),
kSetupConnection: Symbol('kSetupConnection'),
Expand Down
12 changes: 6 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ test('invalid options', t => {
const list = [
{
value: {
destroyTimeout: 'string'
closeTimeout: 'string'
},
message: 'destroyTimeout must be a number > 0'
message: 'closeTimeout must be a number > 0'
},
{
value: {
destroyTimeout: 0
closeTimeout: 0
},
message: 'destroyTimeout must be a number > 0'
message: 'closeTimeout must be a number > 0'
},
{
value: {
Expand Down Expand Up @@ -148,7 +148,7 @@ test('getConnection should error if the url is invalid', t => {
})

test('should terminate inactive connections', async (t) => {
const agent = new Agent11({ destroyTimeout: 200 })
const agent = new Agent11({ closeTimeout: 200 })
t.teardown(() => agent.close())
agent.getConnection(new URL('http://xyz.xyz'))
t.is(1, agent.size)
Expand All @@ -157,7 +157,7 @@ test('should terminate inactive connections', async (t) => {
})

test('shuld keep alive used connections', async (t) => {
const agent = new Agent11({ destroyTimeout: 200 })
const agent = new Agent11({ closeTimeout: 200 })
t.teardown(() => agent.close())
agent.getConnection(new URL('http://xyz.xyz'))
t.is(1, agent.size)
Expand Down

0 comments on commit 7d1e61e

Please sign in to comment.