expr-eval
expr-eval copied to clipboard
Asycnhronous evaluation
Hi,
Would it be possible to add a Asynchronous evaluator ? I am currently using this libray to call a couple of functions dynamically, however I do have a a couple of functions which are asynchronous in nature. Since the evaluation happens instantly, it immediately resolves the pending promise instead of the value.
So the case would be something like this;
Parser.functions.AsyncCall1 = async function() { const res = await api.getAmount(); return res; }
Parser.functions.AsyncCall2 = async function() { const res = await api.getAmount(); return res; }
Parser.evaluateAsync('AsyncCall1() + AsyncCall2()');
Although I do realize this was not the intended use-case.
I'm not sure this would be possible without duplicating essentially the whole evaluator. I agree it would be useful though, so I'll give it some thought.
Made async work in https://github.com/j2L4e/expr-eval/tree/async It passes the original test suite but as you said, it basically required copying the whole thing, so I just changed it to all-async for now.
edit: also minification is broken right now
This would be extremely useful for us too. Currently, we are having to pre-process formulas that may include async functions, execute the async functions, replace their result in the formula, and then evaluate it with expr-eval.
Just want to chime in that this would be a great addition though it would be nice to be able to retain both a synchronous and asynchronous code paths - which might be a bit complicated as already mentioned.
My use case is to remotely load a YAML file with parameters to parse into a dictionary which is then used in the expression eval for this robotics xacro format parser: https://github.com/gkjohnson/xacro-parser.