Created
December 2, 2022 15:49
-
-
Save riemannulus/abe4dae033a3ce763e7f67c7a58a315c to your computer and use it in GitHub Desktop.
StartAsyncForWaitForUntilLeast23NodeAlive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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