Skip to content

Commit

Permalink
fix: treat error same as close
Browse files Browse the repository at this point in the history
might be that close is not always emitted
  • Loading branch information
ianshade committed May 7, 2021
1 parent a910d18 commit 0d05dd0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/peptalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,17 @@ class PepTalk extends EventEmitter implements PepTalkClient, PepTalkJS {
ws.on('message', this.processChunk.bind(this))
resolve(ws)
})
ws.once('error', (err) => {
const close = (err?: any) => {
ws.removeAllListeners()
if (!err) this.ws = Promise.resolve(null)
reject(err)
this.emit('close')
}
ws.once('error', (err) => {
close(err)
})
ws.once('close', () => {
this.ws = Promise.resolve(null)
this.emit('close')
close()
})
})

Expand Down

0 comments on commit 0d05dd0

Please sign in to comment.