public async Task ApplyAsync(IEnumerable <IShard> shards, IAsyncShardOperation operation, CancellationToken cancellationToken)
 {
     foreach (var shard in GetNextOrderingOfShards(shards))
     {
         var shardOperation = operation.PrepareAsync(shard);
         await shardOperation(cancellationToken);
     }
 }
        public async Task <T> ApplyAsync <T>(IEnumerable <IShard> shards, IAsyncShardOperation <T> operation, IExitStrategy <T> exitStrategy, CancellationToken cancellationToken)
        {
            foreach (var shard in GetNextOrderingOfShards(shards))
            {
                var shardOperation = operation.PrepareAsync(shard);
                var result         = await shardOperation(cancellationToken);

                if (result != null && exitStrategy.AddResult(result, shard))
                {
                    Log.Debug("Short-circuiting operation {0} after execution against shard {1}", operation.OperationName, shard);
                    break;
                }
            }
            return(exitStrategy.CompileResults());
        }