How in twilio to do truly async pagination when reading incoming messages in C#

Viewed 14

Im currently using following api for doing message fetching:

    var resoures = await Twilio.Rest.Api.V2010.Account.MessageResource.ReadAsync(
        new Twilio.Rest.Api.V2010.Account.ReadMessageOptions 
        {
            DateSentAfter = DateTime.UtcNow.AddDays(-7)
        },
        restClient
    )

The resource is ResourceSet<MessageResource> type and implementing sync IEnumerable as following

    public IEnumerator<T> GetEnumerator()
    {
        while (_page != null)
        {
            _iterator.Reset();
            while (_iterator.MoveNext())
            {
                if (_options.Limit.HasValue && _processed > _options.Limit.Value)
                {
                    yield break;
                }

                _processed++;
                yield return _iterator.Current;
            }

            if (AutoPaging && _page.HasNextPage())
            {
                FetchNextPage();
                continue;
            }

            break;
        }
    }

Its obvious consequent calls to this method are sync which shouldn't be the case and properties of ResourceSet arent exposed enough to leverage paging in async manner

How to call get result in fully async fashion?

0 Answers
Related