Skip to content

Commit

Permalink
Make waiting for transport start optional. (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell authored Dec 8, 2022
1 parent 187be2d commit 06b59ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Tingle.EventBus/DependencyInjection/EventBusOptions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,6 +15,14 @@ public class EventBusOptions
{
private readonly IList<EventBusTransportRegistrationBuilder> transports = new List<EventBusTransportRegistrationBuilder>();

/// <summary>
/// Whether to wait for the transport to be ready before publishing/cancelling events.
/// Set this to false when not using or starting an <see cref="IHost"/> because the bus and its transports
/// are started in an <see cref="IHostedService"/>.
/// Defaults to <see langword="true"/>.
/// </summary>
public bool WaitTransportStarted { get; set; } = true;

/// <summary>
/// Gets the <see cref="EventBusNamingOptions"/> for the Event Bus.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Tingle.EventBus/Transports/EventBusTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 06b59ce

Please sign in to comment.