Skip to content

[suggestion] Implement async / await #76

Open
@lofcz

Description

@lofcz

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions