-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
Async await support in Functions #57
Comments
Yes, currently this is not supported. Probably this can be written using:
Or maybe adding a The only solution for now is to rewrite your function with sync methods:
|
@davideicardi Thanks for the answer. I've already done in sync mode. I realized that the targeted .NET Framework was 4.0. And this version does not contain async await. I think cause of .NET 4.0 suport ParseAsync will be the best choise. |
|
No, async / await is not supported, and probably never will be. When you write an async method, the compiler performs a LOT of things (creating a class to hoist captured variables, etc), which can't easily be done. Under the hood, we're using Linq expression trees, which doesn't provide any method to do that. You can check this stackoverflow question |
This is a workaround that worked for me store the results from the async task before executing the invoke of the Lambda var interpreter = new Interpreter();
var dictionary = new Dictionary<string, double>();
interpreter.SetFunction("ASYNC_TASK", () => dictionary["ASYNC_TASK"]);
var parsed = interpreter.Parse("ASYNC_TASK() + 1");
// Simulate an async function
dictionary["ASYNC_TASK"] = await Task.FromResult(10);
var result = parsed.Invoke();
Assert.Equal(11.0, result); Also, you can get the Functions that Lambda contains List<Identifier> functionsUsedByExpression = parsed
.Identifiers
.Where(e => e.GetType().Name == "FunctionIdentifier")
.ToList(); |
Hello. I've succesfully integrated DynamicExpresso (.NET Core) in my project, but there is a question with the Functions, that returns Task. Is there support for this kind of Expressions?
Example:
Currentry I receive Exception
The text was updated successfully, but these errors were encountered: