IMessenger.Send behaviour
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 28/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- csharp
- Área
- backend-api-design
Línea de trabajo
Empieza leyendo la API IMessenger.Send y el comportamiento de AsyncRequestMessage que se usan en los ejemplos. Compara los casos Task y Task, y después revisa las pruebas o la documentación existentes sobre la semántica de finalización de los mensajes de solicitud. Se considera terminado cuando el comportamiento está confirmado y documentado explícitamente, o cuando se acuerda un cambio de API específico con pruebas que describan el comportamiento de finalización previsto.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- C#
- Estrellas
- 3.8k
- Forks
- 402
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de CommunityToolkit/dotnet
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicatePosiblemente ocupada @apachezy la tomó hace 121 días. Abiertobug :bug:
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
CommunityToolkit/dotnet#1206 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
CommunityToolkit/dotnet#648 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
CommunityToolkit/dotnet#1218 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
CommunityToolkit/dotnet#1217 ·
Todos los issues de CommunityToolkit/dotnet
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 2 días
-
[Core] IPlatformServices.PrefersDarkTheme: the desktop's theme as the signed-in user sees itAbiertoarea: core bug help wanted ready
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
ZaidX88/sluice#265 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
rate limit at lrclib.netAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
area: remote bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Install a C# EnvironmentAbierto📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
CodeYourFuture/Module-Tools#712 ·