Skip to content

[suggestion] Implement async / await #76

Open
@lofcz

Description

@lofcz
Contributor

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 */

Activity

changed the title [-][suggestion] implement async / await[/-] [+][suggestion] Implement async / await[/+] on Jan 14, 2021
codingseb

codingseb commented on Jan 14, 2021

@codingseb
Owner

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

self-assigned this
on Jan 14, 2021
lofcz

lofcz commented on Jan 14, 2021

@lofcz
ContributorAuthor

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

israellot commented on Jul 30, 2021

@israellot
Contributor

+1 to this feature

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @israellot@lofcz@codingseb

      Issue actions

        [suggestion] Implement async / await · Issue #76 · codingseb/ExpressionEvaluator