Skip to content

Commit 6651c78

Browse files
committed
throttle reconnect to 3 seconds
1 parent 781d5df commit 6651c78

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ export default class RohrpostClient extends EventEmitter {
8585
this.socketState = 'closed'
8686
this.emit('closed') // why past tense? because the socket is already closed and not currently closing
8787
if (!this._normalClose) {
88-
this.emit('reconnecting')
89-
this._createSocket()
88+
setTimeout(() => {
89+
this.emit('reconnecting')
90+
this._createSocket()
91+
}, 3000) // throttle reconnect
9092
}
9193
})
9294

test/all.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('Rohrpost Client', () => {
7373
it('… and reconnect', (done) => {
7474
client.once('open', done)
7575
server.drop = false
76-
})
76+
}).timeout(5000)
7777
it('should automatically resubscribe', (done) => {
7878
// TODO test this for real
7979
client.once('collection-52', (err, data) => {
@@ -93,7 +93,7 @@ describe('Rohrpost Client', () => {
9393
})
9494
it('… and reconnect', (done) => {
9595
client.once('open', done)
96-
})
96+
}).timeout(5000)
9797
it('should close itself', (done) => {
9898
client.close()
9999
client.once('closed', done)

0 commit comments

Comments
 (0)