Tidy up when usage in Flow and Node

This commit is contained in:
Nick O'Leary
2019-01-17 13:18:26 +00:00
parent 901b32297e
commit 490903ca25
5 changed files with 93 additions and 102 deletions

View File

@@ -16,7 +16,6 @@
var util = require("util");
var EventEmitter = require("events").EventEmitter;
var when = require("when");
var redUtil = require("@node-red/util").util;
var Log = require("@node-red/util").log; // TODO: separate module
@@ -92,21 +91,34 @@ Node.prototype.close = function(removed) {
var callback = this._closeCallbacks[i];
if (callback.length > 0) {
promises.push(
when.promise(function(resolve) {
var args = [];
if (callback.length === 2) {
args.push(!!removed);
new Promise((resolve) => {
try {
var args = [];
if (callback.length === 2) {
args.push(!!removed);
}
args.push(() => {
resolve();
});
callback.apply(node, args);
} catch(err) {
// TODO: error thrown in node async close callback
// We've never logged this properly.
resolve();
}
args.push(resolve);
callback.apply(node, args);
})
);
} else {
callback.call(node);
try {
callback.call(node);
} catch(err) {
// TODO: error thrown in node sync close callback
// We've never logged this properly.
}
}
}
if (promises.length > 0) {
return when.settle(promises).then(function() {
return Promise.all(promises).then(function() {
if (this._context) {
return context.delete(this._alias||this.id,this.z);
}
@@ -115,7 +127,7 @@ Node.prototype.close = function(removed) {
if (this._context) {
return context.delete(this._alias||this.id,this.z);
}
return;
return Promise.resolve();
}
};
@@ -138,8 +150,6 @@ Node.prototype.send = function(msg) {
/* istanbul ignore else */
if (node) {
node.receive(msg);
} else {
console.log("trying to send to a node not on this flow",this._wire);
}
return;
} else {
@@ -187,8 +197,6 @@ Node.prototype.send = function(msg) {
}
}
}
} else {
console.log("trying to send to a node not on this flow",this._wire);
}
}
}
@@ -295,4 +303,5 @@ Node.prototype.metric = function(eventname, msg, metricValue) {
Node.prototype.status = function(status) {
this._flow.handleStatus(this,status);
};
module.exports = Node;