fix: clearing timeout when closes (#87)

This commit is contained in:
Pedro Teixeira 2018-02-07 06:43:15 +01:00 committed by David Dias
parent d804244239
commit f8f52665f7

View File

@ -55,23 +55,19 @@ module.exports = (handler) => {
callback = callback || noop
options = options || {}
let closed = false
server.close(callback)
server.once('close', () => {
closed = true
})
setTimeout(() => {
if (closed) {
return
}
const timeout = setTimeout(() => {
log('unable to close graciously, destroying conns')
Object.keys(server.__connections).forEach((key) => {
log('destroying %s', key)
server.__connections[key].destroy()
})
}, options.timeout || CLOSE_TIMEOUT)
server.close(callback)
server.once('close', () => {
clearTimeout(timeout)
})
}
let ipfsId