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

View File

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

View File

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

View File

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