mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Add async context support to Inject node
This commit is contained in:
		@@ -63,21 +63,33 @@ module.exports = function(RED) {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.on("input",function(msg) {
 | 
			
		||||
            try {
 | 
			
		||||
                msg.topic = this.topic;
 | 
			
		||||
                if ( (this.payloadType == null && this.payload === "") || this.payloadType === "date") {
 | 
			
		||||
                    msg.payload = Date.now();
 | 
			
		||||
                } else if (this.payloadType == null) {
 | 
			
		||||
                    msg.payload = this.payload;
 | 
			
		||||
                } else if (this.payloadType === 'none') {
 | 
			
		||||
                    msg.payload = "";
 | 
			
		||||
                } else {
 | 
			
		||||
                    msg.payload = RED.util.evaluateNodeProperty(this.payload,this.payloadType,this,msg);
 | 
			
		||||
            msg.topic = this.topic;
 | 
			
		||||
            if (this.payloadType !== 'flow' && this.payloadType !== 'global') {
 | 
			
		||||
                try {
 | 
			
		||||
                    if ( (this.payloadType == null && this.payload === "") || this.payloadType === "date") {
 | 
			
		||||
                        msg.payload = Date.now();
 | 
			
		||||
                    } else if (this.payloadType == null) {
 | 
			
		||||
                        msg.payload = this.payload;
 | 
			
		||||
                    } else if (this.payloadType === 'none') {
 | 
			
		||||
                        msg.payload = "";
 | 
			
		||||
                    } 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);
 | 
			
		||||
                msg = null;
 | 
			
		||||
            } catch(err) {
 | 
			
		||||
                this.error(err,msg);
 | 
			
		||||
            } else {
 | 
			
		||||
                RED.util.evaluateNodeProperty(this.payload,this.payloadType,this,msg, function(err,res) {
 | 
			
		||||
                    if (err) {
 | 
			
		||||
                        node.error(err,msg);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        msg.payload = res;
 | 
			
		||||
                        node.send(msg);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -368,7 +368,7 @@ function evaluateNodeProperty(value, type, node, msg, callback) {
 | 
			
		||||
    if (callback) {
 | 
			
		||||
        callback(result);
 | 
			
		||||
    } else {
 | 
			
		||||
        return value;
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user