Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make waiting for transport start optional. #483

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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