IMessenger.Send behaviour
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 28/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- csharp
- Ambito
- backend-api-design
Direzione di ricerca
Inizia leggendo l’API IMessenger.Send e il comportamento di AsyncRequestMessage utilizzati negli esempi. Confronta i casi Task e Task, quindi controlla i test o la documentazione esistenti sulla semantica del completamento dei messaggi di richiesta. Il lavoro è completato quando il comportamento è confermato e documentato esplicitamente, oppure quando viene concordata una modifica mirata all’API con test che descrivono il comportamento di completamento previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- C#
- Stelle
- 3.8k
- Fork
- 402
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di CommunityToolkit/dotnet
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicateForse già presa @apachezy l’ha presa 121 giorni fa. Apertabug :bug:
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
CommunityToolkit/dotnet#1206 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
CommunityToolkit/dotnet#648 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
CommunityToolkit/dotnet#1218 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
CommunityToolkit/dotnet#1217 ·
Tutte le issue di CommunityToolkit/dotnet
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 2 giorni
-
area: core bug help wanted ready
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ZaidX88/sluice#265 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
rate limit at lrclib.netAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
area: remote bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Install a C# EnvironmentAperta📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
CodeYourFuture/Module-Tools#712 ·