Add support for RelayCommand that returns a ValueTask
Overview
Add support for RelayCommand that returns a ValueTask.
Currently, the SG works only for the RelayCommand that returns a Task.
In certain scenarios, returning a ValueTask instead of a Task can be more efficient. For instance, a command that returns data from the cache, if available, and initiates a network call only in the event of a cache miss.
API breakdown
// Works currently
[RelayCommand]
private Task DoWork1Async() => Task.CompletedTask;
// To be implemented
[RelayCommand]
private ValueTask DoWork2Async() => ValueTask.CompletedTask;
Usage example
Similar to Task, the method returns ValueTask if the hot path is synchronous. Design decision.
Breaking change?
No
Alternatives
Manually create the Command infra.
Additional context
https://devblogs.microsoft.com/dotnet/understanding-the-whys-whats-and-whens-of-valuetask/
Help us help you
No, just wanted to propose this
I guess this could be done by storing and checking if the return type is a Task or a ValueTask, then later use the return type's value in the generated source-code?