Skip to content

Instantly share code, notes, and snippets.

@skalahonza
Created February 5, 2021 08:13
Show Gist options
  • Save skalahonza/84a52ce4da043b208e94f9a10cbe06a8 to your computer and use it in GitHub Desktop.
Save skalahonza/84a52ce4da043b208e94f9a10cbe06a8 to your computer and use it in GitHub Desktop.
Expose segmented query of Table Storage as IAsyncEnumerable
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