I'm building an API that will do paging and sorting by querying a database that as a lot of entries and I stopped at a point where I'm build methods overloading and could to put that to work well, at least at the proper way I think.
This is a mock up code:
public virtual IAsyncEnumerable<PagedResults<T>> GetPagedItems(int i)
{
return GetPagedItems(null, i);
}
public virtual async IAsyncEnumerable<PagedResults<T>> GetPagedItems(string s, int i)
{
//here I get 2 datasets, one with the items (25 for instance)
//and in the 2nd one I get the total count
var datasets = await GetItemsFromDB<T>();
var items = datasets[0].ToList();
var totalCount = datasets[1].ReadFirst();
yield return new PagedResults<T>
{
Items = items,
TotalCount = totalCount
};
}
My questions is this, in the first method (the one only one parameter) it works but without the 'async' keyword.
In a first implementation I added the async and but I got a warning from visual studio saying that I cannot return a value from an iterator (makes sense), then a added the 'yield async' and it complained that I cannot convert PagedResults to an IAsyncEnumerable<PagedResults>.
I'm wondering if my final implementation it's correct and if it would work on doing the asynchronous streaming if I use the first method.