1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add Force parameter mqtt client.end() when called in disconnect

This commit is contained in:
Phil Day 2022-05-05 16:12:28 +01:00 committed by Steve-Mcl
parent ca204dea2d
commit 3be75fa822

View File

@ -765,11 +765,23 @@ module.exports = function(RED) {
}
callback && typeof callback == "function" && callback();
};
if(node.closing) {
return _callback(false, force);
}
var endCallBack = function endCallBack() {
}
if(!node.client) { return _callback(); }
if(node.closing) { return _callback(); }
let waitEnd = (client, ms) => {
return new Promise( (resolve, reject) => {
node.closing = true;
if(!client) {
resolve();
} else {
const t = setTimeout(reject, ms);
client.end(true, () => {
clearTimeout(t);
resolve()
});
}
});
};
if(node.connected && node.closeMessage) {
node.publish(node.closeMessage, function (err) {
node.client.end(endCallBack);