Add async context support to Inject node

This commit is contained in:
Nick O'Leary 2018-07-07 22:09:55 +01:00
parent 4bcf13cb58
commit afb566b6b4
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 27 additions and 15 deletions

View File

@ -63,21 +63,33 @@ module.exports = function(RED) {
} }
this.on("input",function(msg) { this.on("input",function(msg) {
try { msg.topic = this.topic;
msg.topic = this.topic; if (this.payloadType !== 'flow' && this.payloadType !== 'global') {
if ( (this.payloadType == null && this.payload === "") || this.payloadType === "date") { try {
msg.payload = Date.now(); if ( (this.payloadType == null && this.payload === "") || this.payloadType === "date") {
} else if (this.payloadType == null) { msg.payload = Date.now();
msg.payload = this.payload; } else if (this.payloadType == null) {
} else if (this.payloadType === 'none') { msg.payload = this.payload;
msg.payload = ""; } else if (this.payloadType === 'none') {
} else { msg.payload = "";
msg.payload = RED.util.evaluateNodeProperty(this.payload,this.payloadType,this,msg); } else {
msg.payload = RED.util.evaluateNodeProperty(this.payload,this.payloadType,this,msg);
}
this.send(msg);
msg = null;
} catch(err) {
this.error(err,msg);
} }
this.send(msg); } else {
msg = null; RED.util.evaluateNodeProperty(this.payload,this.payloadType,this,msg, function(err,res) {
} catch(err) { if (err) {
this.error(err,msg); node.error(err,msg);
} else {
msg.payload = res;
node.send(msg);
}
});
} }
}); });
} }

View File

@ -368,7 +368,7 @@ function evaluateNodeProperty(value, type, node, msg, callback) {
if (callback) { if (callback) {
callback(result); callback(result);
} else { } else {
return value; return result;
} }
} }