IMessenger.Send behaviour
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 28/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- csharp
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Bắt đầu bằng cách đọc API IMessenger.Send và hành vi của AsyncRequestMessage được sử dụng trong các ví dụ. So sánh các trường hợp Task và Task, sau đó kiểm tra các bài kiểm thử hoặc tài liệu hiện có về ngữ nghĩa hoàn tất của thông báo yêu cầu. Được xem là hoàn tất khi hành vi đã được xác nhận và ghi lại một cách rõ ràng, hoặc khi một thay đổi API tập trung được thống nhất cùng với các bài kiểm thử mô tả hành vi hoàn tất dự kiến.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
Service registration:
AddSingleton<IMessenger>(WeakReferenceMessenger.Default)
Message registration:
_messenger.Register<AsyncRelayCommandPageViewModel, TestAsyncMessage1>(this, static (r, m) => m.Reply(r.Action1(m)));
Behavour:
Case1:
If Action1 is of type Task<T> and we do following:
string response = await _messenger.Send<TestAsyncMessage1>(new());
private async Task<string> Action1(TestAsyncMessage1 msg)
{
await Task.Delay(TimeSpan.FromSeconds(5));
Trace.WriteLine("Action1 process complete");
return "hello";
}
the response is of type string and contains the value hello.
Case2:
However, if Action1 is of type Task and we do following:
Task response = await _messenger.Send<TestAsyncMessage1>(new());
private async Task Action1(TestAsyncMessage1 msg)
{
await Task.Delay(TimeSpan.FromSeconds(5));
Trace.WriteLine("Action1 process complete");
}
the response is of type Task.
Issue:
In Case1 does the await actually awaits the internal task (Action1) and return the value of the task, in this case the string hello.
In Case2 does the await awaits that the message is sent, but not the internal task (Action1).
So if we want the same behaviour for Case2, where we want the internal task to be completed, we have to do something like:
Task response = await _messenger.Send<TestAsyncMessage1>(new());
await response;
We are now implementation our own solution, using an extension method:
public static class ExtensionMethods
{
public static async Task ProcessTask<TMessage>(this IMessenger messenger, TMessage message)
where TMessage : AsyncRequestMessage<Task>
{
var task = await messenger.Send(message);
await task;
}
public static Task ProcessTask<TMessage>(this IMessenger messenger)
where TMessage : AsyncRequestMessage<Task>, new()
=> messenger.ProcessTask(new TMessage());
}
Making it possible to do following:
await _messenger.ProcessTask<TestAsyncMessage1>(new());
Description
Depening on the return type, we have different behavour.
Is this wanted? Would it make sense to add something like ProcessTask to the library to extend the functionality?
Regression
No response
Steps to reproduce
Microsoft Visual Studio Professional 2022 (64-bit) - Current
Version 17.12.4
CommunityToolkit.Mvvm
Version 8.2.2
Expected behavior
See description of bug.
Screenshots
No response
IDE and version
VS 2022
IDE version
Version 17.12.4
Nuget packages
- CommunityToolkit.Common
- CommunityToolkit.Diagnostics
- CommunityToolkit.HighPerformance
- CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.2.2
Additional context
No response
Help us help you
Yes, I'd like to be assigned to work on this item
- Ngôn ngữ chính
- C#
- Star
- 3.8k
- Fork
- 402
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của CommunityToolkit/dotnet
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicateCó thể đã có người làm @apachezy đã nhận 121 ngày trước. Đang mởbug :bug:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
CommunityToolkit/dotnet#1206 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
CommunityToolkit/dotnet#648 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
CommunityToolkit/dotnet#1218 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
CommunityToolkit/dotnet#1217 ·
Tất cả issue của CommunityToolkit/dotnet
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[Core] IPlatformServices.PrefersDarkTheme: the desktop's theme as the signed-in user sees itĐang mởarea: core bug help wanted ready
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ZaidX88/sluice#265 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
rate limit at lrclib.netĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
area: remote bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Install a C# EnvironmentĐang mở📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
CodeYourFuture/Module-Tools#712 ·