diff --git a/src/Tingle.EventBus/DependencyInjection/EventBusOptions.cs b/src/Tingle.EventBus/DependencyInjection/EventBusOptions.cs index ad4b7269..cca52e1d 100644 --- a/src/Tingle.EventBus/DependencyInjection/EventBusOptions.cs +++ b/src/Tingle.EventBus/DependencyInjection/EventBusOptions.cs @@ -1,4 +1,5 @@ -using Polly.Retry; +using Microsoft.Extensions.Hosting; +using Polly.Retry; using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; using Tingle.EventBus; @@ -14,6 +15,14 @@ public class EventBusOptions { private readonly IList transports = new List(); + /// + /// Whether to wait for the transport to be ready before publishing/cancelling events. + /// Set this to false when not using or starting an because the bus and its transports + /// are started in an . + /// Defaults to . + /// + public bool WaitTransportStarted { get; set; } = true; + /// /// Gets the for the Event Bus. /// diff --git a/src/Tingle.EventBus/Transports/EventBusTransport.cs b/src/Tingle.EventBus/Transports/EventBusTransport.cs index 91e64783..b90d16c9 100644 --- a/src/Tingle.EventBus/Transports/EventBusTransport.cs +++ b/src/Tingle.EventBus/Transports/EventBusTransport.cs @@ -119,6 +119,8 @@ public async Task StopAsync(CancellationToken cancellationToken) private Task WaitStartedAsync(CancellationToken cancellationToken) { + if (!BusOptions.WaitTransportStarted) return Task.CompletedTask; + var tsk = startedTcs.Task; if (tsk.Status is TaskStatus.RanToCompletion) return tsk; return Task.Run(() => tsk, cancellationToken); // allows for cancellation by caller