refactor: transparently resolve traversal invocation arg promises

This commit is contained in:
cha0s 2019-06-05 20:12:07 -05:00
parent 80b57e0e7f
commit e690967cb8

View File

@ -85,7 +85,23 @@ class Context extends Map {
return node[step.key];
case 'invoke':
const args = step.args.map((arg) => arg.get(this));
// Any arg promises will be resolved; the arg values will be passed
// transparently to the invocation.
let hasPromise = false;
for (let i = 0; i < args.length; i++) {
if (args[i] instanceof Promise) {
hasPromise = true;
break;
}
}
if (hasPromise) {
return Promise.all(args).then((args) => {
return fastApply(previousNode, node, args);
});
}
else {
return fastApply(previousNode, node, args);
}
}
}