feelin icon indicating copy to clipboard operation
feelin copied to clipboard

Support evaluation of async functions

Open richardmward opened this issue 4 years ago • 2 comments

This question is purely a matter of interest - no expectation either way! The https://github.com/EdgeVerve/feel project has a very convenient feature in that it allows context functions to be async, for example:

const expression = `{ promiseTrue: promise(true), constantTrue: true }`;
const context = {
    promise: (v) => Promise.resolve(v)
};
feel.parse(expression).build(context).then(console.log);
// { promiseTrue: true, constantTrue: true }

For comparison (and completely expected at the moment) would result in a promise still being in the result. It's easy enough to traverse the results to collate all the leaf nodes and wait for them with a Promise.all, but I just thought I'd ask if something like the above would have a place in the feelin project or not?

const expression = `{ promiseTrue: promise(true), constantTrue: true }`;
const context = {
    promise: (v) => Promise.resolve(v)
};
const result = feelin.evaluate(expression, context);
console.log(result)
// { promiseTrue: Promise { true }, constantTrue: true }

richardmward avatar Apr 15 '20 14:04 richardmward