Files
Ngino/src/ReverseLlama.Client/TunnelWorker.cs
T
lucretia 97807b25ee
Build & Deploy / build (push) Failing after 43s
Initial commit
2026-07-14 19:03:38 +02:00

31 lines
853 B
C#

using Microsoft.Extensions.Hosting;
namespace ReverseLlama.Client;
internal sealed class TunnelWorker : BackgroundService
{
private readonly TunnelClient _client;
private readonly IHostApplicationLifetime _lifetime;
public TunnelWorker(TunnelClient client, IHostApplicationLifetime lifetime)
{
_client = client;
_lifetime = lifetime;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
await _client.RunAsync(stoppingToken);
}
finally
{
// RunAsync only returns when cancelled or replaced by a newer client.
// Stop gracefully (exit 0) so service recovery does not restart us
// into a reconnect fight with the replacement.
_lifetime.StopApplication();
}
}
}