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

Replace some instances of when with Promise

This commit is contained in:
Nick O'Leary 2018-04-24 23:49:57 +01:00
parent 9a972b0b8a
commit 5866d414ce
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
5 changed files with 12 additions and 20 deletions

View File

@ -14,11 +14,6 @@
* limitations under the License.
**/
var when = require("when");
var fs = require("fs");
var path = require("path");
var events = require("../../events");
var registry = require("./registry");
var loader = require("./loader");
var installer = require("./installer");
@ -51,7 +46,7 @@ function enableNodeSet(typeOrId) {
return registry.getNodeInfo(typeOrId);
});
}
return when.resolve(nodeSet);
return Promise.resolve(nodeSet);
});
}

View File

@ -15,7 +15,6 @@
**/
var when = require("when");
var path = require("path");
var fs = require("fs");
@ -73,7 +72,7 @@ function checkExistingModule(module,version) {
}
function installModule(module,version) {
//TODO: ensure module is 'safe'
return when.promise(function(resolve,reject) {
return new Promise(function(resolve,reject) {
var installName = module;
var isUpgrade = false;
try {
@ -177,7 +176,7 @@ function reportRemovedModules(removedNodes) {
}
function uninstallModule(module) {
return when.promise(function(resolve,reject) {
return new Promise(function(resolve,reject) {
if (/[\s;]/.test(module)) {
reject(new Error(log._("server.install.invalid")));
return;
@ -228,9 +227,9 @@ function checkPrereq() {
) {
log.info(log._("server.palette-editor.disabled"));
paletteEditorEnabled = false;
return when.resolve();
return Promise.resolve();
} else {
return when.promise(function(resolve) {
return new Promise(function(resolve) {
child_process.execFile(npmCommand,['-v'],function(err) {
if (err) {
log.info(log._("server.palette-editor.npm-not-found"));

View File

@ -173,7 +173,7 @@ function loadNodeFiles(nodeFiles) {
}
function loadNodeConfig(fileInfo) {
return when.promise(function(resolve) {
return new Promise(function(resolve) {
var file = fileInfo.file;
var module = fileInfo.module;
var name = fileInfo.name;
@ -298,7 +298,7 @@ function loadNodeSet(node) {
var nodeDir = path.dirname(node.file);
var nodeFn = path.basename(node.file);
if (!node.enabled) {
return when.resolve(node);
return Promise.resolve(node);
} else {
}
try {
@ -322,7 +322,7 @@ function loadNodeSet(node) {
if (loadPromise == null) {
node.enabled = true;
node.loaded = true;
loadPromise = when.resolve(node);
loadPromise = Promise.resolve(node);
}
return loadPromise;
} catch(err) {
@ -339,7 +339,7 @@ function loadNodeSet(node) {
}
}
}
return when.resolve(node);
return Promise.resolve(node);
}
}
@ -371,13 +371,13 @@ function addModule(module) {
// TODO: nls
var e = new Error("module_already_loaded");
e.code = "module_already_loaded";
return when.reject(e);
return Promise.reject(e);
}
try {
var moduleFiles = localfilesystem.getModuleFiles(module);
return loadNodeFiles(moduleFiles);
} catch(err) {
return when.reject(err);
return Promise.reject(err);
}
}

View File

@ -14,7 +14,6 @@
* limitations under the License.
**/
var when = require("when");
var fs = require("fs");
var path = require("path");

View File

@ -16,7 +16,6 @@
//var UglifyJS = require("uglify-js");
var util = require("util");
var when = require("when");
var path = require("path");
var fs = require("fs");
@ -133,7 +132,7 @@ function saveNodeList() {
if (settings.available()) {
return settings.set("nodes",moduleList);
} else {
return when.reject("Settings unavailable");
return Promise.reject("Settings unavailable");
}
}