CommunityToolkit / CommunityToolkit/dotnet

Add support for RelayCommand that returns a ValueTask

Open
#1,031 1 comment 0 reactions 0 assignees View on GitHub
feature request :mailbox_with_mail:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### 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

```cs
// 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.