feelin
feelin copied to clipboard
Support evaluation of async functions
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 }
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:.
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.