mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Use native Promise instead of when.js
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
var clone = require("clone");
|
||||
var log = require("../../log");
|
||||
var when = require("when");
|
||||
|
||||
var settings;
|
||||
var contexts = {};
|
||||
@@ -59,14 +58,14 @@ function load() {
|
||||
try{
|
||||
plugin = require("./"+plugins[pluginName].module);
|
||||
}catch(err){
|
||||
return when.reject(new Error(log._("context.error-module-not-loaded", {module:plugins[pluginName].module})));
|
||||
return Promise.reject(new Error(log._("context.error-module-not-loaded", {module:plugins[pluginName].module})));
|
||||
}
|
||||
} else {
|
||||
plugin = plugins[pluginName].module;
|
||||
}
|
||||
externalContexts[pluginName] = plugin(config);
|
||||
}else{
|
||||
return when.reject(new Error(log._("context.error-module-not-defined", {storage:pluginName})));
|
||||
return Promise.reject(new Error(log._("context.error-module-not-defined", {storage:pluginName})));
|
||||
}
|
||||
}
|
||||
for(var plugin in externalContexts){
|
||||
@@ -78,10 +77,10 @@ function load() {
|
||||
if(externalContexts.hasOwnProperty(plugins["default"])){
|
||||
externalContexts["default"] = externalContexts[plugins["default"]];
|
||||
}else{
|
||||
return when.reject(new Error(log._("context.error-invalid-default-module", {storage:plugins["default"]})));
|
||||
return Promise.reject(new Error(log._("context.error-invalid-default-module", {storage:plugins["default"]})));
|
||||
}
|
||||
}
|
||||
return when.all(promises);
|
||||
return Promise.all(promises);
|
||||
} else {
|
||||
noContextStorage = true;
|
||||
return externalContexts["_"].open();
|
||||
@@ -224,7 +223,7 @@ function deleteContext(id,flowId) {
|
||||
delete contexts[contextId];
|
||||
return externalContexts["_"].delete(contextId);
|
||||
}else{
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +242,7 @@ function clean(flowConfig) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return when.all(promises);
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
function close() {
|
||||
@@ -253,7 +252,7 @@ function close() {
|
||||
promises.push(externalContexts[plugin].close());
|
||||
}
|
||||
}
|
||||
return when.all(promises);
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
var fs = require('fs-extra');
|
||||
var path = require("path");
|
||||
var when = require("when");
|
||||
var util = require("../../util");
|
||||
|
||||
function getStoragePath(storageBaseDir, scope) {
|
||||
@@ -67,10 +66,10 @@ function loadFile(storagePath){
|
||||
if(exists === true){
|
||||
return fs.readFile(storagePath, "utf8");
|
||||
}else{
|
||||
return when.resolve(undefined);
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
}).catch(function(err){
|
||||
throw when.reject(err);
|
||||
throw Promise.reject(err);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,11 +79,11 @@ function LocalFileSystem(config){
|
||||
}
|
||||
|
||||
LocalFileSystem.prototype.open = function(){
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
LocalFileSystem.prototype.close = function(){
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
LocalFileSystem.prototype.getAsync = function(scope, key) {
|
||||
@@ -96,7 +95,7 @@ LocalFileSystem.prototype.getAsync = function(scope, key) {
|
||||
return undefined
|
||||
}
|
||||
}).catch(function(err){
|
||||
return when.reject(err);
|
||||
return Promise.reject(err);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -110,7 +109,7 @@ LocalFileSystem.prototype.setAsync =function(scope, key, value) {
|
||||
var str = JSON.stringify(obj, undefined, 4);
|
||||
return fs.outputFile(storagePath + ".json", str, {encoding:"utf8",flag:"w+"});
|
||||
}).catch(function(err){
|
||||
return when.reject(err);
|
||||
return Promise.reject(err);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -123,7 +122,7 @@ LocalFileSystem.prototype.keysAsync = function(scope){
|
||||
return []
|
||||
}
|
||||
}).catch(function(err){
|
||||
return when.reject(err);
|
||||
return Promise.reject(err);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -135,7 +134,7 @@ LocalFileSystem.prototype.delete = function(scope){
|
||||
LocalFileSystem.prototype.clean = function(activeNodes){
|
||||
var self = this;
|
||||
return fs.readdir(self.storageBaseDir).then(function(dirs){
|
||||
return when.all(dirs.reduce(function(result, item){
|
||||
return Promise.all(dirs.reduce(function(result, item){
|
||||
if(item !== "global" && activeNodes.indexOf(item) === -1){
|
||||
result.push(fs.remove(path.join(self.storageBaseDir,item)));
|
||||
}
|
||||
@@ -143,9 +142,9 @@ LocalFileSystem.prototype.clean = function(activeNodes){
|
||||
},[]));
|
||||
}).catch(function(err){
|
||||
if(err.code == 'ENOENT') {
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}else{
|
||||
return when.reject(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -15,18 +15,17 @@
|
||||
**/
|
||||
|
||||
var util = require("../../util");
|
||||
var when = require("when");
|
||||
|
||||
function Memory(config){
|
||||
this.data = {};
|
||||
}
|
||||
|
||||
Memory.prototype.open = function(){
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
Memory.prototype.close = function(){
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
Memory.prototype.get = function(scope, key) {
|
||||
@@ -46,7 +45,7 @@ Memory.prototype.set =function(scope, key, value) {
|
||||
Memory.prototype.keys = function(scope){
|
||||
if(!this.data[scope]){
|
||||
return [];
|
||||
}
|
||||
}
|
||||
if (scope !== "global") {
|
||||
return Object.keys(this.data[scope]);
|
||||
} else {
|
||||
@@ -57,15 +56,15 @@ Memory.prototype.keys = function(scope){
|
||||
};
|
||||
|
||||
Memory.prototype.getAsync = function(scope, key) {
|
||||
return when.resolve(this.get(scope, key));
|
||||
return Promise.resolve(this.get(scope, key));
|
||||
};
|
||||
|
||||
Memory.prototype.setAsync =function(scope, key, value) {
|
||||
return when.resolve(this.set(scope, key, value));
|
||||
return Promise.resolve(this.set(scope, key, value));
|
||||
};
|
||||
|
||||
Memory.prototype.keysAsync = function(scope){
|
||||
return when.resolve(this.keys(scope));
|
||||
return Promise.resolve(this.keys(scope));
|
||||
};
|
||||
|
||||
Memory.prototype.delete = function(scope){
|
||||
|
Reference in New Issue
Block a user