Created
February 5, 2021 08:13
-
-
Save skalahonza/84a52ce4da043b208e94f9a10cbe06a8 to your computer and use it in GitHub Desktop.
Expose segmented query of Table Storage as IAsyncEnumerable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Azure.Cosmos.Table; | |
using System.Collections.Generic; | |
using System.Runtime.CompilerServices; | |
using System.Threading; | |
public static class TableQueryExtensions | |
{ | |
public static async IAsyncEnumerable<T> ExecuteAsync<T>(this TableQuery<T> query, [EnumeratorCancellation] CancellationToken ct = default) | |
{ | |
TableContinuationToken token = null; | |
do | |
{ | |
var segment = await query.ExecuteSegmentedAsync(token, ct); | |
token = segment.ContinuationToken; | |
foreach (var item in segment) | |
yield return item; | |
} while (token != null && !ct.IsCancellationRequested); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment