Skip to content

Instantly share code, notes, and snippets.

@riemannulus
Created December 2, 2022 15:49
Show Gist options
  • Save riemannulus/abe4dae033a3ce763e7f67c7a58a315c to your computer and use it in GitHub Desktop.
Save riemannulus/abe4dae033a3ce763e7f67c7a58a315c to your computer and use it in GitHub Desktop.
StartAsyncForWaitForUntilLeast23NodeAlive
public async Task StartAsync(CancellationToken ctx)
{
_cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(ctx);
Task transportTask = _transport.StartAsync(ctx);
await _transport.WaitForRunningAsync();
try
{
await _protocol.BootstrapAsync(_seeds, TimeSpan.FromSeconds(1), 3, ctx);
}
catch (PeerDiscoveryException pde)
{
_logger.Error(
pde,
"Peer discovery exception occurred during {FName}.",
nameof(StartAsync));
}
_transport.ProcessMessageHandler.Register(
HandleMessageAsync(_cancellationTokenSource.Token));
await WaitForUntilLeast23NodeAlive(ctx);
_logger.Debug("All peers are alive. Starting gossip...");
Running = true;
await Task.WhenAny(
transportTask,
RefreshTableAsync(_cancellationTokenSource.Token),
RebuildTableAsync(_cancellationTokenSource.Token),
HeartbeatTask(_cancellationTokenSource.Token));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment