Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Mar 18, 2022
1 parent abf6b7a commit f449552
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/agent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { InvalidArgumentError } = require('./core/errors')
const { kClients, kRunning } = require('./core/symbols')
const { kClients, kRunning, kClose, kDestroy } = require('./core/symbols')
const DispatcherBase = require('./dispatcher-base')
const Pool = require('./pool')
const Client = require('./client')
Expand Down Expand Up @@ -117,7 +117,7 @@ class Agent extends DispatcherBase {
return dispatcher.dispatch(opts, handler)
}

async _close () {
async [kClose] () {
const closePromises = []
for (const ref of this[kClients].values()) {
const client = ref.deref()
Expand All @@ -130,7 +130,7 @@ class Agent extends DispatcherBase {
await Promise.all(closePromises)
}

async _destroy (err) {
async [kDestroy] (err) {
const destroyPromises = []
for (const ref of this[kClients].values()) {
const client = ref.deref()
Expand Down
8 changes: 5 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const {
kConnector,
kMaxRedirections,
kMaxRequests,
kCounter
kCounter,
kClose,
kDestroy
} = require('./core/symbols')

const kClosedResolve = Symbol('kClosedResolve')
Expand Down Expand Up @@ -279,7 +281,7 @@ class Client extends DispatcherBase {
return this[kNeedDrain] < 2
}

async _close () {
async [kClose] () {
return new Promise((resolve) => {
if (!this[kSize]) {
this.destroy(resolve)
Expand All @@ -289,7 +291,7 @@ class Client extends DispatcherBase {
})
}

async _destroy (err) {
async [kDestroy] (err) {
return new Promise((resolve) => {
const requests = this[kQueue].splice(this[kPendingIdx])
for (let i = 0; i < requests.length; i++) {
Expand Down
2 changes: 2 additions & 0 deletions lib/core/symbols.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
kClose: Symbol('close'),
kDestroy: Symbol('destroy'),
kUrl: Symbol('url'),
kWriting: Symbol('writing'),
kResuming: Symbol('resuming'),
Expand Down
5 changes: 3 additions & 2 deletions lib/dispatcher-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
ClientClosedError,
InvalidArgumentError
} = require('./core/errors')
const { kDestroy, kClose } = require('./core/symbols')

const kDestroyed = Symbol('destroyed')
const kClosed = Symbol('closed')
Expand Down Expand Up @@ -69,7 +70,7 @@ class DispatcherBase extends Dispatcher {
}

// Should not error.
this._close()
this[kClose]()
.then(() => this.destroy())
.then(() => {
queueMicrotask(onClosed)
Expand Down Expand Up @@ -119,7 +120,7 @@ class DispatcherBase extends Dispatcher {
}

// Should not error.
this._destroy(err).then(() => {
this[kDestroy](err).then(() => {
queueMicrotask(onDestroyed)
})
}
Expand Down
6 changes: 3 additions & 3 deletions lib/pool-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const DispatcherBase = require('./dispatcher-base')
const FixedQueue = require('./node/fixed-queue')
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl } = require('./core/symbols')
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy } = require('./core/symbols')
const PoolStats = require('./pool-stats')

const kClients = Symbol('clients')
Expand Down Expand Up @@ -111,7 +111,7 @@ class PoolBase extends DispatcherBase {
return this[kStats]
}

async _close () {
async [kClose] () {
if (this[kQueue].isEmpty()) {
return Promise.all(this[kClients].map(c => c.close()))
} else {
Expand All @@ -121,7 +121,7 @@ class PoolBase extends DispatcherBase {
}
}

async _destroy (err) {
async [kDestroy] (err) {
while (true) {
const item = this[kQueue].shift()
if (!item) {
Expand Down
6 changes: 3 additions & 3 deletions lib/proxy-agent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { kProxy } = require('./core/symbols')
const { kProxy, kClose, kDestroy } = require('./core/symbols')
const { URL } = require('url')
const Agent = require('./agent')
const DispatcherBase = require('./dispatcher-base')
Expand Down Expand Up @@ -31,11 +31,11 @@ class ProxyAgent extends DispatcherBase {
)
}

async _close () {
async [kClose] () {
await this[kAgent].close()
}

async _destroy () {
async [kDestroy] () {
await this[kAgent].destroy()
}
}
Expand Down

0 comments on commit f449552

Please sign in to comment.