Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RelayCommand that returns a ValueTask #1031

Open
egvijayanand opened this issue Dec 19, 2024 · 1 comment
Open

Add support for RelayCommand that returns a ValueTask #1031

egvijayanand opened this issue Dec 19, 2024 · 1 comment
Labels
feature request 📬 A request for new changes to improve functionality

Comments

@egvijayanand
Copy link

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

@egvijayanand egvijayanand added the feature request 📬 A request for new changes to improve functionality label Dec 19, 2024
@TheVeryStarlk
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request 📬 A request for new changes to improve functionality
Projects
None yet
Development

No branches or pull requests

2 participants