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

Add callback handling to memory plugin

This commit is contained in:
HirokiUchikawa 2018-06-26 11:36:37 +09:00
parent f2fa26fb07
commit cce7ac09d0

View File

@ -28,30 +28,67 @@ Memory.prototype.close = function(){
return Promise.resolve(); return Promise.resolve();
}; };
Memory.prototype.get = function(scope, key) { Memory.prototype.get = function(scope, key, callback) {
if(!this.data[scope]){ var value;
return undefined; 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]){ if(!this.data[scope]){
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){ Memory.prototype.keys = function(scope, callback){
if(!this.data[scope]){ var values = [];
return []; 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") { if(callback){
return Object.keys(this.data[scope]); callback(null, values);
} else { } else {
return Object.keys(this.data[scope]).filter(function (key) { return values;
return key !== "set" && key !== "get" && key !== "keys";
});
} }
}; };