Updated closing logic

This commit is contained in:
delvedor
2018-12-19 19:49:29 +01:00
parent 7a181ff9ac
commit fc6d12ad3e
3 changed files with 16 additions and 10 deletions

View File

@ -110,12 +110,13 @@ class Connection {
}
// TODO: write a better closing logic
close () {
close (callback = () => {}) {
debug('Closing connection', this.id)
if (this._openRequests > 0) {
setTimeout(() => this.close(), 1000)
setTimeout(() => this.close(callback), 1000)
} else {
this._agent.destroy()
callback()
}
}