Skip to content

Register Async Functions #12

Description

@PCastelletto

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions