fix(node): refactor execute method to use async/await for operation execution
This commit is contained in:
parent
c4f4735626
commit
4595b5f5f6
@ -89,24 +89,21 @@ class NodeRecipe {
|
|||||||
* @returns {NodeDish}
|
* @returns {NodeDish}
|
||||||
*/
|
*/
|
||||||
execute(dish) {
|
execute(dish) {
|
||||||
return this.opList.reduce((prev, curr) => {
|
return (async () => {
|
||||||
|
let currentInput = dish;
|
||||||
|
|
||||||
const runOp = (input) => {
|
for (const curr of this.opList) {
|
||||||
|
// Check if it's an operation object or a direct function
|
||||||
if (Object.prototype.hasOwnProperty.call(curr, "op") &&
|
if (Object.prototype.hasOwnProperty.call(curr, "op") &&
|
||||||
Object.prototype.hasOwnProperty.call(curr, "args")) {
|
Object.prototype.hasOwnProperty.call(curr, "args")) {
|
||||||
return curr.op(input, curr.args);
|
currentInput = await curr.op(currentInput, curr.args);
|
||||||
|
} else {
|
||||||
|
currentInput = await curr(currentInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
return curr(input);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
if (prev && typeof prev.then === "function") {
|
|
||||||
return prev.then(runOp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return runOp(prev);
|
return currentInput;
|
||||||
}, dish);
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user