mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Add callback handling to memory plugin
This commit is contained in:
		@@ -28,30 +28,67 @@ Memory.prototype.close = function(){
 | 
			
		||||
    return Promise.resolve();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Memory.prototype.get = function(scope, key) {
 | 
			
		||||
    if(!this.data[scope]){
 | 
			
		||||
        return undefined;
 | 
			
		||||
Memory.prototype.get = function(scope, key, callback) {
 | 
			
		||||
    var value;
 | 
			
		||||
    try{
 | 
			
		||||
        if(this.data[scope]){
 | 
			
		||||
            value = util.getMessageProperty(this.data[scope], key);
 | 
			
		||||
        }
 | 
			
		||||
    }catch(err){
 | 
			
		||||
        if(callback){
 | 
			
		||||
            callback(err);
 | 
			
		||||
        }else{
 | 
			
		||||
            throw err;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(callback){
 | 
			
		||||
        callback(null, value);
 | 
			
		||||
    } else {
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
    return util.getMessageProperty(this.data[scope],key);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Memory.prototype.set =function(scope, key, value) {
 | 
			
		||||
Memory.prototype.set =function(scope, key, value, callback) {
 | 
			
		||||
    if(!this.data[scope]){
 | 
			
		||||
        this.data[scope] = {};
 | 
			
		||||
    }
 | 
			
		||||
    util.setMessageProperty(this.data[scope],key,value);
 | 
			
		||||
    try{
 | 
			
		||||
        util.setMessageProperty(this.data[scope],key,value);
 | 
			
		||||
    }catch(err){
 | 
			
		||||
        if(callback){
 | 
			
		||||
            callback(err);
 | 
			
		||||
        }else{
 | 
			
		||||
            throw err;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(callback){
 | 
			
		||||
        callback(null);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Memory.prototype.keys = function(scope){
 | 
			
		||||
    if(!this.data[scope]){
 | 
			
		||||
        return [];
 | 
			
		||||
Memory.prototype.keys = function(scope, callback){
 | 
			
		||||
    var values = [];
 | 
			
		||||
    try{
 | 
			
		||||
        if(this.data[scope]){
 | 
			
		||||
            if (scope !== "global") {
 | 
			
		||||
                values = Object.keys(this.data[scope]);
 | 
			
		||||
            } else {
 | 
			
		||||
                values = Object.keys(this.data[scope]).filter(function (key) {
 | 
			
		||||
                    return key !== "set" && key !== "get" && key !== "keys";
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }catch(err){
 | 
			
		||||
        if(callback){
 | 
			
		||||
            callback(err);
 | 
			
		||||
        }else{
 | 
			
		||||
            throw err;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (scope !== "global") {
 | 
			
		||||
        return Object.keys(this.data[scope]);
 | 
			
		||||
    if(callback){
 | 
			
		||||
        callback(null, values);
 | 
			
		||||
    } else {
 | 
			
		||||
        return Object.keys(this.data[scope]).filter(function (key) {
 | 
			
		||||
            return key !== "set" && key !== "get" && key !== "keys";
 | 
			
		||||
        });
 | 
			
		||||
        return values;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user