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

[suggestion] Implement async / await #76

Open
lofcz opened this issue Jan 14, 2021 · 3 comments
Open

[suggestion] Implement async / await #76

lofcz opened this issue Jan 14, 2021 · 3 comments

Comments

@lofcz
Copy link
Contributor

lofcz commented Jan 14, 2021

Currently this is not included in todo / roadmap document here - https://github.com/codingseb/ExpressionEvaluator/wiki/ExpressionEvaluator-Todo-List

Implementing async / await (with priority on await) would greatly increase flexibility of EE. C# is becoming more and more asynchronous with each new version and by using async patterns we can free current thread while external work is being processed (querying a database, creating/saving a stream, waiting for an external library to do some work...). This is critical for web applications where threadpool is very limited and we need to free our threads as often as possible.

This suggestion hence proposes that async / await keywords would be recognized when parsing scripts.

Backend:

public class Main {
     public staic void Main() {
          ExpressionEvaluator eval = new();
          eval .StaticTypesForExtensionsMethods.Add(typeof(MyClassExt));
          eval.Variables = new Dictionary<string, object> {
               { "SomeAsyncMethod", new Func<int>(async () => await someAwaitableJobReturningInt())} }
          }

          eval.ScriptEvaluate(script);
     }
}

Script:

myResult = await SomeAsyncMethod();

Note that we would also need to support this on extension methods.

For the sake of supporting various syntaxes keywords should be remappable.

myResult = waitfor SomeAsyncMethod(); /* waitfor = await */
@lofcz lofcz changed the title [suggestion] implement async / await [suggestion] Implement async / await Jan 14, 2021
@codingseb
Copy link
Owner

Yes it would be great.
I need some reflection on how to do it.
I keep it open as a todo 😃

@codingseb codingseb self-assigned this Jan 14, 2021
@lofcz
Copy link
Contributor Author

lofcz commented Jan 14, 2021

Core of the problem here is that we need to "await" EventHandler which we can't do as it returns void. Something like DefferedEvents would be needed here - https://pedrolamas.github.io/DeferredEvents/

what do you think?

@israellot
Copy link
Contributor

+1 to this feature

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

No branches or pull requests

3 participants