I was wondering what your thoughts would be on passing a cancellation token to each of the funcs in the .net implementation. This can then be checked, while the code is running, to understand if leadership has been lost.
I took a look at implementing leadership election in dotnetcore a while back using etcd and used this pattern. Full code here, simple example below.
var election = new ElectionRunner(
isNowMaster: (cancellationToken) =>{
while (!cancellationToken.IsCancellationRequested)
{
Console.WriteLine("We're Master!!");
Task.Delay(TimeSpan.FromSeconds(3)).Wait();
}
},
isNowSecondary: (cancellationToken) =>{
while (!cancellationToken.IsCancellationRequested)
{
Console.WriteLine("We're secondary");
Task.Delay(TimeSpan.FromSeconds(3)).Wait();
}
},
electionTimeoutSec: 15);
I'm unclear on how feasible this is in the Metaparticle code but if there is agreement that it is an worthwhile addition I can investigate further and hopefully create a PR.
I was wondering what your thoughts would be on passing a cancellation token to each of the funcs in the .net implementation. This can then be checked, while the code is running, to understand if leadership has been lost.
I took a look at implementing leadership election in dotnetcore a while back using etcd and used this pattern. Full code here, simple example below.
I'm unclear on how feasible this is in the Metaparticle code but if there is agreement that it is an worthwhile addition I can investigate further and hopefully create a PR.