fix(node): enable asynchronous operation support in Node.js API
This commit is contained in:
parent
cfc84f543c
commit
212a2c68c3
@ -88,16 +88,17 @@ class NodeRecipe {
|
||||
* @param {NodeDish} dish
|
||||
* @returns {NodeDish}
|
||||
*/
|
||||
execute(dish) {
|
||||
return this.opList.reduce((prev, curr) => {
|
||||
// CASE where opList item is op and args
|
||||
async execute(dish) {
|
||||
let prev = dish;
|
||||
for (const curr of this.opList) {
|
||||
if (Object.prototype.hasOwnProperty.call(curr, "op") &&
|
||||
Object.prototype.hasOwnProperty.call(curr, "args")) {
|
||||
return curr.op(prev, curr.args);
|
||||
prev = await curr.op(prev, curr.args);
|
||||
} else {
|
||||
prev = await curr(prev);
|
||||
}
|
||||
// CASE opList item is just op.
|
||||
return curr(prev);
|
||||
}, dish);
|
||||
}
|
||||
return prev;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -324,10 +324,10 @@ export function help(input) {
|
||||
* @returns {NodeDish} of the result
|
||||
* @throws {TypeError} if invalid recipe given.
|
||||
*/
|
||||
export function bake(input, recipeConfig) {
|
||||
const recipe = new NodeRecipe(recipeConfig);
|
||||
export async function bake(input, recipeConfig) {
|
||||
const recipe = new NodeRecipe(recipeConfig);
|
||||
const dish = ensureIsDish(input);
|
||||
return recipe.execute(dish);
|
||||
return await recipe.execute(dish);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user