Async/Await Feature for WebMap Blazor
Last updated
Last updated
In WebMap Blazor, we need the MessageBox Show and the InputBoxShow to be awaited. For this reason, it is necessary to have an asynchronous architecture for methods that call the MessageBox Show or the InputBox Show. For this documentation purposes we are calling every "awaitable" call, like that, an AwaitableCall.
But, what happens when a method that calls an AwaitableCall, is called inside another method? And then another method called those methods.
We can have a chain of async and await calls. But how can we determine in the migration where to put an await and where to put an async?
For this reason, we decided to build a Graph, to have all the dependencies between client code methods and calls. And, using a service, we are going to save in a Hash set all the async methods. By doing this, we can ask in the transformation rules if a method is registered as an async method.
A graph looking like this:
As you can see the MyMethod should be async. Why? Because if you follow the route of calls and dependencies, the last call is to an AwaitableCall.
This is the service that saves the dependencies graph(This graph is not saving or marking the async methods, just saving the call dependencies between methods), and then HashSet that has all the methods that should be async.
Where is the graph builded?. Well, let's take a look at the AsyncAwaitsCollector.
Here in the Collect method, the searcher will execute in every CSMethod node to build the dependencies.
Here we don’t need to register as method roots the methods coming from System or UpgradeHelpers.
Then when the Graph is built, we can now register all the async methods. Let’s jump to the BlazorAsyncAwaitsCollectorTask.
Here, the MarkAsyncMethods is called to go through the graph and register the methods that need to be async.
Using this feature we are supporting the next scenarios in migration:
This will be converted to
This will be transformed to
Every method and call that has a MessageBox call and is not a simple notification, is going to have an async modifier.
This will be transformed to
This will be transformed to
This scenario is not supported. The CreateInstance is async by the Async/Await feature
If you have a scenario where an async method is being called in the FormLoad, the constructor or the DefInstance(from VBUC Migration), there will be a lot of issues. Please refer to the section