Comparing version
24
hiio.js
@@ -360,5 +360,11 @@ 'use strict'; | ||
this.session.on('close', () => { | ||
this.session.on('close', async () => { | ||
this.connected = false | ||
if (this.keepalive && typeof this.reconn === 'function') { | ||
await new Promise((rv, rj) => { | ||
setTimeout(() => { | ||
rv() | ||
}, this.reconnDelay) | ||
}) | ||
this.debug && console.log('Connect closed, reconnect...') | ||
@@ -681,2 +687,8 @@ this.reconn() | ||
on (evt, callback) { | ||
for (let a of this.pool) { | ||
a.on(evt, callback) | ||
} | ||
} | ||
} | ||
@@ -799,9 +811,11 @@ | ||
/** | ||
* 延迟重连不能使用setTimeout,因为timer循环会在下一个循环开始执行, | ||
* 而在本次循环,error的处理会先执行,此时,error事件还没有监听。 | ||
*/ | ||
if (options.keepalive) { | ||
newReq.reconn = () => { | ||
options.sessionRequest = newReq | ||
setTimeout(() => { | ||
this.connect(url, options) | ||
newReq.init() | ||
}, newReq.reconnDelay) | ||
this.connect(url, options) | ||
newReq.init() | ||
} | ||
@@ -808,0 +822,0 @@ } |
{ | ||
"name": "gohttp", | ||
"version": "4.1.0-beta2", | ||
"version": "4.1.0-beta3", | ||
"description": "http & https client for HTTP/1.1 and HTTP/2", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
82747
0.45%1871
0.65%