Closed ensemblebd closed 1 year ago
Hi! Perhaps I'm misunderstanding something, I'm puzzled with your statement that async methods in the BaseVM subclass aren't really async and therefore must be wrapped in Task.Run. Here's the callstack of a method from the SimpleList example that was turned into async:
As you can see, it's async all the way to the SignalR hub method.
But if you're referring specifically to the Action
form, then you're right, it won't handle async properly and should be refactored into the former.
Thank you! You are right for sure, boils down to the Action specifically. I hadn't fully tested comparatively to validate. Will go ahead and close this one out; can be solved by using non-action, no core modifications required. Thank you again :)
Hi dsuryd!! So have been playing with this on one of my projects, and I ended up having to modify the VMSerializer.cs file to accommodate my needs.
Wanted to see if perhaps there is a better way, or if this is something for potential consideration via a PR?
When you have something like this in a BaseVM subclass:
Three problems present themselves.
It's not really async, it just has the markup. So it must be wrapped in
Task.Run(async ()=> { .. })
That unleashes the VM's when you have multiple VM operations running at once. They otherwise run synchronously and block each other, despite being marked async and having an await operation inside AND returning typeof Task. Not sure why, above my head. But wrapping inTask.Run
produces truly async execution.However the Task.Run occurs too fast, and the BaseVM's
ChangedProperties
collects changes before thePushChanges
is called asynchronously, causing data to not be sent back to frontend. So my action signatures must then become:Which brings up potential problem 3.
If an error occurs in an async operation, dot net core crashes completely. So my pattern becomes:
While this works well, I end up with a VM that has duplicate code in every method call, and the simplicity is lost by the ever expansive code.
So my proposed solution is: // DotNetifyLib.Core/BaseVM/VMSerializer.cs # 182
Thus my actions can simply become (far cleaner, less repeated code, easier to read for regular developers):
Wanted to get your thoughts on this when you get a chance, thank you!!