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

Good question! I guess from the users point of view, it makes a lot of sense. Function calls for instance can be async, as they may fetch, i.e. external data.

To be honest with you though, the interpreter part of feelin needs substantial rework and, if you currently rely on edgeVerve/feel, please continue to do so :wink:.

nikku avatar Apr 15 '20 16:04 nikku

As it is, I'm not actually using edgeVerge/feel (other than to play around with) as I am unable to get it working in a browser environment. At this stage, I was just comparing the options available (in the FEEL space), and that seemed like a useful feature that I'd ask about.

richardmward avatar Apr 15 '20 21:04 richardmward