Skip to content

Commit

Permalink
fix(browser support): do not use process.nextTick without check that …
Browse files Browse the repository at this point in the history
…it exists (#1136)
  • Loading branch information
nosovk authored Aug 3, 2020
1 parent eedc2b2 commit 963e554
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ var reInterval = require('reinterval')
var validations = require('./validations')
var xtend = require('xtend')
var debug = require('debug')('mqttjs:client')
var nextTick = process ? process.nextTick : function (callback) { setTimeout(callback, 0) }
var setImmediate = global.setImmediate || function (callback) {
// works in node v0.8
process.nextTick(callback)
nextTick(callback)
}
var defaultConnectOptions = {
keepalive: 60,
Expand Down Expand Up @@ -303,7 +304,7 @@ MqttClient.prototype._setupStream = function () {

function nextTickWork () {
if (packets.length) {
process.nextTick(work)
nextTick(work)
} else {
var done = completeParse
completeParse = null
Expand Down Expand Up @@ -838,8 +839,8 @@ MqttClient.prototype.end = function (force, opts, cb) {
debug('end :: (%s) :: finish :: calling _cleanUp with force %s', that.options.clientId, force)
that._cleanUp(force, () => {
debug('end :: finish :: calling process.nextTick on closeStores')
// var boundProcess = process.nextTick.bind(null, closeStores)
process.nextTick(closeStores.bind(that))
// var boundProcess = nextTick.bind(null, closeStores)
nextTick(closeStores.bind(that))
}, opts)
}

Expand Down
4 changes: 2 additions & 2 deletions lib/connect/wx.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ function buildStream (client, opts) {
stream.destroy = destroyRef

var self = this
process.nextTick(function () {
setTimeout(function () {
socketTask.close({
fail: function () {
self._destroy(new Error())
}
})
})
}, 0)
}.bind(stream)

bindEventHandler()
Expand Down
4 changes: 2 additions & 2 deletions lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ Store.prototype.createStream = function () {

destroyed = true

process.nextTick(function () {
setTimeout(function () {
self.emit('close')
})
}, 0)
}

return stream
Expand Down

0 comments on commit 963e554

Please sign in to comment.