public IMultiLevelCursorIterator <TInput, TOutput> Create <TDTO, TInput, TOutput>( ITwitterPageIterator <ITwitterResult <TDTO> > pageIterator, Func <TDTO, TInput[]> transform, Func <TInput[], Task <TOutput[]> > getChildItems, int maxPageSize) { var iterator = new MultiLevelCursorIterator <TInput, TOutput>( async() => { var userIdsPage = await pageIterator.NextPage().ConfigureAwait(false); return(new CursorPageResult <TInput, string> { Items = transform(userIdsPage.Content.DataTransferObject), NextCursor = userIdsPage.NextCursor, IsLastPage = userIdsPage.IsLastPage }); }, async inputs => { var userIdsToAnalyze = inputs.Take(maxPageSize).ToArray(); var friends = await getChildItems(userIdsToAnalyze).ConfigureAwait(false); return(new MultiLevelPageProcessingResult <TInput, TOutput> { Items = friends, AssociatedParentItems = userIdsToAnalyze, }); }); return(iterator); }
public async Task Act() { if (_iterator.NextCursor != null) { throw new InvalidOperationException("Cannot run with pre executed iterator"); } while (!_iterator.Completed) { var page = await _iterator.NextPage(); _resultPages.Add(page); } }