Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register Async Functions #12

Open
PCastelletto opened this issue Jan 2, 2025 · 2 comments
Open

Register Async Functions #12

PCastelletto opened this issue Jan 2, 2025 · 2 comments

Comments

@PCastelletto
Copy link

Greetings and Happy New Year :3!
I have a question!, How can i register and await async functions?.
I tried something like this:

import jsonata

class JsonataFunctions:
    class Asum(jsonata.Jsonata.JFunctionCallable):
        async def call(self, inputs, args):
            result = await (args[0] + args[1])
            return result


def test_async_jsonata():
    expression_input = {}
    expression_str = """ {"test": $aSum(1, 2)}"""
    expression = jsonata.Jsonata(expression_str)
    expression.register_function(
        "aSum", jsonata.Jsonata.JFunction(JsonataFunctions.Asum(), "<nn:n>"))
    return expression.evaluate(expression_input)

But every instance of a function in the expression is replaced with a coroutine and never awaited.
In the example:
{'test': <coroutine object JsonataFunctions.Asum.call at 0x117827bc0>}

Maybe im doing something wrong or the library doesn't support it, i hope you can help me!, good work btw :D!

@rayokota
Copy link
Owner

rayokota commented Jan 3, 2025

Hi @PCastelletto , this is not yet supported.

@PCastelletto
Copy link
Author

Thanks for the quick answer!
Is adding this feature part of the future plans of the project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants