private bool AddChildParentNeedsWatch(IActorRef parent, IActorRef child)
{
const bool weDontHaveTailRecursion = true;
while (weDontHaveTailRecursion)
{
if (_parent2Children.TryAdd(parent, ImmutableHashSet<IActorRef>.Empty.Add(child)))
return true; //child was successfully added
IImmutableSet<IActorRef> children;
if (_parent2Children.TryGetValue(parent, out children))
{
if (_parent2Children.TryUpdate(parent, children.Add(child), children))
return false; //child successfully added
}
}
}