Skip to content

Commit

Permalink
fix: useless bind
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Jul 18, 2023
1 parent 331cb28 commit ec9de31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class MqttClient extends EventEmitter {
this.stream.pipe(writable)

// Suppress connection errors
this.stream.on('error', streamErrorHandler.bind(this))
this.stream.on('error', streamErrorHandler)

// Echo stream close
this.stream.on('close', () => {
Expand Down Expand Up @@ -890,7 +890,7 @@ class MqttClient extends EventEmitter {
'end :: finish :: calling process.nextTick on closeStores',
)
// const boundProcess = nextTick.bind(null, closeStores)
nextTick(closeStores.bind(this))
nextTick(closeStores)
},
opts,
)
Expand Down
17 changes: 8 additions & 9 deletions test/abstract_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,17 @@ module.exports = (server, config) => {
const client = connect()

client.once('end', () => {
const timeout = setTimeout(done.bind(null), 200)
const timeout = setTimeout(() => done(), 200)
client.once('end', () => {
clearTimeout(timeout)
done(new Error('end was emitted twice'))
})
client.end()
})

client.once('connect', client.end.bind(client))
client.once('connect', () => {
client.end()
})
})

it('should stop ping timer after end called', function _test(done) {
Expand Down Expand Up @@ -232,8 +234,7 @@ module.exports = (server, config) => {

// after 200ms manually invoke client.end
setTimeout(() => {
const boundEnd = client.end.bind(client)
boundEnd()
client.end.callbind(client)
}, 200)
})

Expand All @@ -247,7 +248,7 @@ module.exports = (server, config) => {
connectTimeout: 10,
reconnectPeriod: 20,
})
setTimeout(done.bind(null), 1000)
setTimeout(() => done(), 1000)
const endCallback = () => {
assert.strictEqual(
spy.callCount,
Expand All @@ -259,8 +260,7 @@ module.exports = (server, config) => {
const spy = sinon.spy(endCallback)
client.on('end', spy)
setTimeout(() => {
client.end.bind(client)
client.end()
client.end.call(client)
}, 300)
})
})
Expand Down Expand Up @@ -2887,8 +2887,7 @@ module.exports = (server, config) => {
})
// bind client.end so that when it is called it is automatically passed in the done callback
setTimeout(() => {
const boundEnd = client.end.bind(client, done)
boundEnd()
client.end.call(client, done)
}, 50)
})

Expand Down

0 comments on commit ec9de31

Please sign in to comment.