Lately I got quite spoiled by all the quality of life features C#/.NET is providing. I noticed the similarity in basic syntax of Enfusion script with C# and was eager to take a look at it. However, there is one thing, that I feel like I am missing, from a modern scripting/programming language. Some sort of handling asynchronous code in the language itself.
So I went for a quest of finding the solution for asynchronous coding with ChatGPT. I first thought, the best idea would be to create some code generator for workbench, that would be able to rewrite some arbitrarty Generator syntax into a basic class with switch case as a means of keeping a state of the method progress. And then using the generator syntax to create Coroutines like in Unity. Easy, right? However, I quickly realized that doing that without goto: statement is going to be extra hard and would require tremendous skills and work, that I lack and was not going to give to this project.
Obviously, there are ways, of doing it by creating something like a TaskCompletionSource and filling it from GetGame().GetCallqueue().CallLater(...). Still ,you would have to chain those with ContinueWith method, and its well ... ugly.
The next option, probably the least liked of them (however I am quite use to it), is the Observable pattern. That still seemed like it could work for Enfusion, however if I was to do it, I would like it to have the fluent form. That still seemed somewhat feasible even without extension methods. If I was able to just copy the rewrites of all the Observable generators as class methods.
While I was thinking about it I realized, that there might actually be a better way to write the the continuation methods of the Task class and basically do ContinueWith(x).Unwrap() in one call as ContinueWithAsync(x). Well, there you have it. "Ok" way to write asynchronous code in Enfusion.
Now there is one thing - this should actually be a part of a platform, so that people can accept Task<T> all around their code.
Also ... having GetGame().GetCallqueue().CallLaterAsync(...) that would return Task would then look like great idea.
Well ... and after that, it might actually be very close to writing something similiar to generator syntax that would be able to create this chaining under the hood.
So my question is - should I write some equivalent to TPL for Reforger as a mod/package or are you planning to do some support for asynchronous coding yourself?
PS:
Just for illustration, I add a reference to a Developer commentary of a classic game that I really liked, this whole thing reminded me of.
PPS: I have yet to write a single line of real code. This was just a case study.