is async supported?
jonathanstanley opened this issue · 2 comments
jonathanstanley commented
nice work!
I was wondering if there is an approach that would handle async?
let fn = createFn('a + b(3)')
fn({ a: 2,b:x=>Promise.resolve(x)}) // 5also, it isn't clear why github repo uses createFn and npm uses script in the first example
dy commented
Ah, I updated readme in github after publishing to npm. Take github as the latest doc.
As for async - it depends on what kind of async you want.
- You can try reimplementing JS async syntax in your mini-language like
a + await b(3), for that you'd need to define unaryasyncoperator. - You can make all evaluators async by default, so that they would wait for result of async function. This way you'd write normal expressions
a + b(3), but they would be async under the hood. For that you'd need to defineoperator('+', async (a,b) => await a + await b ). (I need to check if that'd work - worst case you'd need to write own evaluator of AST, which is not very difficult, example is here)
jonathanstanley commented
thanks!