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
|
* @param {NodeDish} dish
|
||||||
* @returns {NodeDish}
|
* @returns {NodeDish}
|
||||||
*/
|
*/
|
||||||
execute(dish) {
|
async execute(dish) {
|
||||||
return this.opList.reduce((prev, curr) => {
|
let prev = dish;
|
||||||
// CASE where opList item is op and args
|
for (const curr of this.opList) {
|
||||||
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(prev, curr.args);
|
prev = await curr.op(prev, curr.args);
|
||||||
|
} else {
|
||||||
|
prev = await curr(prev);
|
||||||
}
|
}
|
||||||
// CASE opList item is just op.
|
}
|
||||||
return curr(prev);
|
return prev;
|
||||||
}, dish);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -324,10 +324,10 @@ export function help(input) {
|
|||||||
* @returns {NodeDish} of the result
|
* @returns {NodeDish} of the result
|
||||||
* @throws {TypeError} if invalid recipe given.
|
* @throws {TypeError} if invalid recipe given.
|
||||||
*/
|
*/
|
||||||
export function bake(input, recipeConfig) {
|
export async function bake(input, recipeConfig) {
|
||||||
const recipe = new NodeRecipe(recipeConfig);
|
const recipe = new NodeRecipe(recipeConfig);
|
||||||
const dish = ensureIsDish(input);
|
const dish = ensureIsDish(input);
|
||||||
return recipe.execute(dish);
|
return await recipe.execute(dish);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user