fix(node): preserve sync bake() API by dynamically chaining async operations
This commit is contained in:
parent
8402c1cafb
commit
b5e8260129
@ -88,14 +88,21 @@ class NodeRecipe {
|
|||||||
* @param {NodeDish} dish
|
* @param {NodeDish} dish
|
||||||
* @returns {NodeDish}
|
* @returns {NodeDish}
|
||||||
*/
|
*/
|
||||||
async execute(dish) {
|
execute(dish) {
|
||||||
let prev = dish;
|
return this.opList.reduce((prev, curr) => {
|
||||||
for (const curr of this.opList) {
|
|
||||||
if (Object.prototype.hasOwnProperty.call(curr, "op") &&
|
const runOp = (input) => {
|
||||||
Object.prototype.hasOwnProperty.call(curr, "args")) {
|
if (Object.prototype.hasOwnProperty.call(curr, "op") &&
|
||||||
prev = await curr.op(prev, curr.args);
|
Object.prototype.hasOwnProperty.call(curr, "args")) {
|
||||||
} else {
|
return curr.op(input, curr.args);
|
||||||
prev = await curr(prev);
|
}
|
||||||
|
|
||||||
|
return curr(input);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (prev && typeof prev.then === 'function') {
|
||||||
|
return prev.then(runOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return prev;
|
return prev;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user