I am building a client for continuously consuming new records from a data source. The integration is pull-based and my client periodically queries the data source for new records. I'm using IAsyncEnumerable as a return type for this continuous stream of new records. Here is the gist of the method in question:
public async IAsyncEnumerable<Record> StreamRecords(...)
{
while (!cancellationToken.IsCancellationRequested)
{
using var response = await _httpClient.SendAsync(request, cancellationToken);
var records = _parser.Parse(response.Content);
foreach (var r in records) yield return r;
await Task.Delay(waitPeriod, cancellationToken);
}
}
Is this an appropriate use of IAsyncEnumerable? This stream should be "never ending" or "continuous" (at least until cancellationToken or error).