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();
};
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;
}
};