Refactor: extract method createLoadPromise

No variable renames, just lines moved.
This commit is contained in:
Håkon Løvdal 2023-09-17 18:58:00 +02:00
parent 71bdd65b8a
commit 3bf1667181

View File

@ -344,30 +344,9 @@ function loadNodeSet(node) {
} else { } else {
} }
try { try {
var loadPromise = null;
var r = require(node.file); var r = require(node.file);
r = r.__esModule ? r.default : r; r = r.__esModule ? r.default : r;
if (typeof r === "function") { return createLoadPromise(node, r);
var red = registryUtil.createNodeApi(node);
var promise = r(red);
if (promise != null && typeof promise.then === "function") {
loadPromise = promise.then(function() {
node.enabled = true;
node.loaded = true;
return node;
}).catch(function(err) {
node.err = err;
return node;
});
}
}
if (loadPromise == null) {
node.enabled = true;
node.loaded = true;
loadPromise = Promise.resolve(node);
}
return loadPromise;
} catch(err) { } catch(err) {
node.err = err; node.err = err;
var stack = err.stack; var stack = err.stack;
@ -391,6 +370,31 @@ function loadNodeSet(node) {
} }
return Promise.resolve(node); return Promise.resolve(node);
} }
function createLoadPromise(node, r) {
var loadPromise = null;
if (typeof r === "function") {
var red = registryUtil.createNodeApi(node);
var promise = r(red);
if (promise != null && typeof promise.then === "function") {
loadPromise = promise.then(function () {
node.enabled = true;
node.loaded = true;
return node;
}).catch(function (err) {
node.err = err;
return node;
});
}
}
if (loadPromise == null) {
node.enabled = true;
node.loaded = true;
loadPromise = Promise.resolve(node);
}
return loadPromise;
}
} }
async function loadPlugin(plugin) { async function loadPlugin(plugin) {