-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Currently, to leave cluster before termination one needs to subscribe to RegisterOnMemberRemoved
, do Leave(cluster.SelfAddress)
and wait for member removal event.
This pattern is very easy to implement wrong. There are also edge cases when event doesn't guarantee arrive (member is in Joining state etc.), thus very easy to hang the process.
Situation becomes more complicated with support of CancellationToken etc.
I'd want to propose to add a convenience method Task LeaveAsync()
into the Cluster.
The example code could look like this:
// with or without cancellation token
await Cluster.Get(_actorSystem).LeaveAsync(cancellationToken);
await _actorSystem.Terminate();
Naive implementation as extension method, just for reference:
public static Task LeaveAsync(this Cluster cluster)
{
var tcs = new TaskCompletionSource<bool>();
cluster.RegisterOnMemberRemoved(() => { tcs.TrySetResult(true); });
cluster.Leave(cluster.SelfAddress);
return tcs.Task;
}