UI threading work

This commit is contained in:
TheXamlGuy
2024-01-13 13:47:26 +00:00
parent 70e0ae9492
commit 66f4bb8757
5 changed files with 35 additions and 5 deletions
+6 -2
View File
@@ -6,9 +6,11 @@ namespace Hyperbar;
public class Mediator(IServiceProvider provider) :
IMediator
{
private readonly SynchronizationContext? context = SynchronizationContext.Current;
private readonly ConditionalWeakTable<Type, dynamic> subjects = [];
public async ValueTask PublishAsync<TNotification>(TNotification notification,
public ValueTask PublishAsync<TNotification>(TNotification notification,
CancellationToken cancellationToken = default)
where TNotification :
INotification
@@ -26,8 +28,10 @@ public class Mediator(IServiceProvider provider) :
foreach (INotificationHandler<TNotification> handler in handlers)
{
await handler.Handle(notification, cancellationToken);
context?.Post(async state => await handler.Handle(notification, cancellationToken), null);
}
return ValueTask.CompletedTask;
}
public ValueTask<TResponse> SendAsync<TResponse>(IRequest<TResponse> request,