Skip to content

Commit

Permalink
pull out iterating tasks' result to ProcessCacheMultiGetResponseTaskR…
Browse files Browse the repository at this point in the history
…esult
  • Loading branch information
poppoerika committed May 10, 2022
1 parent 09ae9d7 commit 0512667
Showing 1 changed file with 18 additions and 36 deletions.
54 changes: 18 additions & 36 deletions Momento/ScsDataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,7 @@ public async Task<CacheMultiGetResponse> MultiGetAsync(string cacheName, List<st
}

await Task.WhenAll(tasks);
foreach (Task<CacheMultiGetResponse> t in tasks)
{
if (t.Result.SuccessfulResponse() is not null)
{
successResponses.Add(t.Result.SuccessfulResponse());
}
if (t.Result.FailedResponse() is not null)
{
failedResponses.Add(t.Result.FailedResponse());
}
}

ProcessCacheMultiGetResponseTaskResult(tasks, successResponses, failedResponses);
return new CacheMultiGetResponse(successResponses, failedResponses);
}

Expand All @@ -112,18 +101,7 @@ public async Task<CacheMultiGetResponse> MultiGetAsync(string cacheName, List<by
}

await Task.WhenAll(tasks);
foreach (Task<CacheMultiGetResponse> t in tasks)
{
if (t.Result.SuccessfulResponse() is not null)
{
successResponses.Add(t.Result.SuccessfulResponse());
}
if (t.Result.FailedResponse() is not null)
{
failedResponses.Add(t.Result.FailedResponse());
}
}

ProcessCacheMultiGetResponseTaskResult(tasks, successResponses, failedResponses);
return new CacheMultiGetResponse(successResponses, failedResponses);
}

Expand All @@ -138,18 +116,7 @@ public async Task<CacheMultiGetResponse> MultiGetAsync(string cacheName, List<Ca
}

await Task.WhenAll(tasks);
foreach (Task<CacheMultiGetResponse> t in tasks)
{
if (t.Result.SuccessfulResponse() is not null)
{
successResponses.Add(t.Result.SuccessfulResponse());
}
if (t.Result.FailedResponse() is not null)
{
failedResponses.Add(t.Result.FailedResponse());
}
}

ProcessCacheMultiGetResponseTaskResult(tasks, successResponses, failedResponses);
return new CacheMultiGetResponse(successResponses, failedResponses);
}

Expand Down Expand Up @@ -271,6 +238,21 @@ private async Task<CacheMultiGetResponse> SendMultiGetAsync(string cacheName, By

}

private void ProcessCacheMultiGetResponseTaskResult(List<Task<CacheMultiGetResponse>> tasks, List<CacheGetResponse> successResponses, List<CacheMultiGetFailureResponse> failedResponses)
{
foreach (Task<CacheMultiGetResponse> t in tasks)
{
if (t.Result.SuccessfulResponse() is not null)
{
successResponses.Add(t.Result.SuccessfulResponse());
}
if (t.Result.FailedResponse() is not null)
{
failedResponses.Add(t.Result.FailedResponse());
}
}
}

private ByteString Convert(byte[] bytes)
{
return ByteString.CopyFrom(bytes);
Expand Down

0 comments on commit 0512667

Please sign in to comment.