dotnet-cqrs/Svrnty.CQRS.Events.Abstractions/EventStore/IEventEmitter.cs

30 lines
1.2 KiB
C#

using System.Collections.Generic;
using Svrnty.CQRS.Events.Abstractions.EventStore;
using System.Threading;
using System.Threading.Tasks;
namespace Svrnty.CQRS.Events.Abstractions.EventStore;
/// <summary>
/// Service for emitting events from command handlers.
/// Events are stored and delivered to subscribers based on their subscriptions.
/// </summary>
public interface IEventEmitter
{
/// <summary>
/// Emit an event with the specified correlation ID.
/// </summary>
/// <param name="event">The event to emit.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The sequence number assigned to this event.</returns>
Task<long> EmitAsync(ICorrelatedEvent @event, CancellationToken cancellationToken = default);
/// <summary>
/// Emit multiple events with the same correlation ID in a batch.
/// </summary>
/// <param name="events">The events to emit.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Dictionary mapping event IDs to their sequence numbers.</returns>
Task<Dictionary<string, long>> EmitBatchAsync(IEnumerable<ICorrelatedEvent> events, CancellationToken cancellationToken = default);
}