using Elsa.Mediator;
using Elsa.Mediator.Contracts;
using Elsa.Workflows.Runtime.Contracts;
using Elsa.Workflows.Runtime.Notifications;
namespace Elsa.Workflows.Runtime.Services;
///
/// Relies on the to publish the received request as a domain event from a background worker.
///
public class BackgroundTaskDispatcher : ITaskDispatcher
{
private readonly INotificationSender _eventPublisher;
///
/// Constructor.
///
public BackgroundTaskDispatcher(INotificationSender eventPublisher) => _eventPublisher = eventPublisher;
///
public async Task DispatchAsync(RunTaskRequest request, CancellationToken cancellationToken = default) => await _eventPublisher.SendAsync(request, NotificationStrategy.Background, cancellationToken);
}