public bool InitUnsubscriber(IActorRef unsubscriber, ActorSystem system) { if (system == null) { return(false); } return(_initiallySubscribedOrUnsubscriber.Match().With <Left <IImmutableSet <IActorRef> > >(v => { if (_initiallySubscribedOrUnsubscriber.CompareAndSet(v, Either.Right(unsubscriber))) { if (_debug) { Publish(new Debug(SimpleName(this), GetType(), string.Format("initialized unsubscriber to: {0} registering {1} initial subscribers with it", unsubscriber, v.Value.Count))); } v.Value.ForEach(RegisterWithUnsubscriber); } else { InitUnsubscriber(unsubscriber, system); } }).With <Right <IActorRef> >(presentUnsubscriber => { if (_debug) { Publish(new Debug(SimpleName(this), GetType(), string.Format("not using unsubscriber {0}, because already initialized with {1}", unsubscriber, presentUnsubscriber))); } }).WasHandled); }