-
Notifications
You must be signed in to change notification settings - Fork 15
/
IMessagingHost.cs
34 lines (30 loc) · 1.26 KB
/
IMessagingHost.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) TotalSoft.
// This source code is licensed under the MIT license.
using System;
using System.Threading;
using System.Threading.Tasks;
namespace NBB.Messaging.Host
{
public interface IMessagingHost
{
public Task StartAsync(CancellationToken cancellationToken = default);
public Task StopAsync(CancellationToken cancellationToken = default);
public void ScheduleRestart(TimeSpan delay = default);
public bool IsRunning();
}
public static class MessagingHostExtensions
{
/// <summary>
/// Attempts to gracefully stop the host with the given timeout.
/// </summary>
/// <param name="host">The <see cref="IMessagingHost"/> to stop.</param>
/// <param name="timeout">The timeout for stopping gracefully. Once expired the
/// server may terminate any remaining active connections.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
public static async Task StopAsync(this IMessagingHost host, TimeSpan timeout)
{
using var cts = new CancellationTokenSource(timeout);
await host.StopAsync(cts.Token).ConfigureAwait(false);
}
}
}