expr-eval icon indicating copy to clipboard operation
expr-eval copied to clipboard

Asycnhronous evaluation

Open m-nab opened this issue 5 years ago • 5 comments

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.

m-nab avatar Apr 06 '20 14:04 m-nab

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.

silentmatt avatar Apr 10 '20 17:04 silentmatt

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

j2L4e avatar Nov 19 '20 20:11 j2L4e

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.

strykeio avatar May 18 '21 13:05 strykeio

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.

gkjohnson avatar Nov 19 '22 01:11 gkjohnson