public Task<IEnumerable<LoadBalancedConnection>> GetConnections(
[CanBeNull] bool? ensureIdentical = null,
CancellationToken cancellationToken = default(CancellationToken))
{
// ReSharper disable PossibleNullReferenceException, AssignNullToNotNullAttribute
return Task.WhenAll(
Connections.Select(c => c.GetLoadBalancedConnection(ensureIdentical, cancellationToken)))
.ContinueWith(
t => (IEnumerable<LoadBalancedConnection>)t.Result,
cancellationToken,
TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion,
TaskScheduler.Current);
// ReSharper restore PossibleNullReferenceException, AssignNullToNotNullAttribute
}
}