| | | 1 | | using Elsa.Mediator.Contexts; |
| | | 2 | | using Elsa.Mediator.Contracts; |
| | | 3 | | using Elsa.Mediator.Middleware.Notification; |
| | | 4 | | using Microsoft.Extensions.DependencyInjection; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Mediator.PublishingStrategies; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Invokes event handlers in parallel and does not wait for the result. |
| | | 10 | | /// </summary> |
| | | 11 | | public class BackgroundProcessingStrategy : IEventPublishingStrategy |
| | | 12 | | { |
| | | 13 | | /// <inheritdoc /> |
| | | 14 | | public async Task PublishAsync(NotificationStrategyContext context) |
| | | 15 | | { |
| | 1 | 16 | | var notificationsChannel = context.ServiceProvider.GetRequiredService<INotificationsChannel>(); |
| | 1 | 17 | | var notificationContext = context.NotificationContext; |
| | 1 | 18 | | var queuedContext = new NotificationContext( |
| | 1 | 19 | | notificationContext.Notification, |
| | 1 | 20 | | NotificationStrategy.Sequential, |
| | 1 | 21 | | notificationContext.ServiceProvider, |
| | 1 | 22 | | notificationContext.CancellationToken); |
| | | 23 | | |
| | 1 | 24 | | await notificationsChannel.Writer.WriteAsync(queuedContext, context.CancellationToken); |
| | 1 | 25 | | } |
| | | 26 | | } |