private void HandleGetClusterShardingStats(GetClusterShardingStats message) { var sender = Sender; Task.WhenAll( _aliveRegions.Select(regionActor => regionActor.Ask <ShardRegionStats>(GetShardRegionStats.Instance, message.Timeout).ContinueWith(r => Tuple.Create(regionActor, r.Result), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion)) ).ContinueWith(allRegionStats => { if (allRegionStats.IsCanceled) { return(new ClusterShardingStats(ImmutableDictionary <Address, ShardRegionStats> .Empty)); } if (allRegionStats.IsFaulted) { throw allRegionStats.Exception; //TODO check if this is the right way } var regions = allRegionStats.Result.ToImmutableDictionary(i => { Address regionAddress = i.Item1.Path.Address; Address address = (regionAddress.HasLocalScope && regionAddress.System == Cluster.SelfAddress.System) ? Cluster.SelfAddress : regionAddress; return(address); }, j => j.Item2); return(new ClusterShardingStats(regions)); }, TaskContinuationOptions.ExecuteSynchronously).PipeTo(sender); }