<commit_before>﻿using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Gfycat
{
    /// <summary>
    /// Enumerates the contents of an <see cref="IFeed{T}"/>
    /// </summary>
    /// <typeparam name="T">The type of item to enumerate</typeparam>
    public struct FeedEnumerator<T> : IAsyncEnumerator<T>
    {
        internal FeedEnumerator(GfycatClient client, IFeed<T> feed, RequestOptions defaultOptions)
        {
            _options = defaultOptions;
            _client = client;
            _currentFeed = feed;
            _currentEnumerator = _currentFeed.Content.GetEnumerator();
        }
        internal readonly RequestOptions _options;
        internal readonly GfycatClient _client;
        IFeed<T> _currentFeed;
        IEnumerator<T> _currentEnumerator;

        public T Current => _currentEnumerator.Current;
        
        public void Dispose()
        {
            // we don't need to do anything
        }

        /// <summary>
        /// Attempts to move to the next item in the current page of content. If there is no content in the current page, it retrieves the next page and returns the result of that content's move next
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> MoveNext(CancellationToken cancellationToken)
        {
            if (!_currentEnumerator.MoveNext())
            {
                RequestOptions newOptions = _options.Clone();
                newOptions.CancellationToken = cancellationToken;

                _currentFeed = await _currentFeed.GetNextPageAsync(newOptions);
                _currentEnumerator = _currentFeed.Content.GetEnumerator();
                return _currentEnumerator.MoveNext();
            }<commit_msg>Fixed feeds doing infinte loops<commit_after>﻿using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

namespace Gfycat
{
    /// <summary>
    /// Enumerates the contents of an <see cref="IFeed{T}"/>
    /// </summary>
    /// <typeparam name="T">The type of item to enumerate</typeparam>
    public class FeedEnumerator<T> : IAsyncEnumerator<T>
    {
        internal FeedEnumerator(GfycatClient client, IFeed<T> feed, RequestOptions defaultOptions)
        {
            _options = defaultOptions;
            _client = client;
            _currentFeed = feed;
            _currentEnumerator = _currentFeed.Content.GetEnumerator();
        }
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        internal readonly GfycatClient _client;

        internal readonly RequestOptions _options;
        IFeed<T> _currentFeed;
        IEnumerator<T> _currentEnumerator;

        public T Current => _currentEnumerator.Current;
        
        public void Dispose()
        {
            // we don't need to do anything
        }

        /// <summary>
        /// Attempts to move to the next item in the current page of content. If there is no content in the current page, it retrieves the next page and returns the result of that content's move next
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> MoveNext(CancellationToken cancellationToken)
        {
            if (!_currentEnumerator.MoveNext())
            {
                if (string.IsNullOrWhiteSpace(_currentFeed.Cursor))
                    return false;

                RequestOptions newOptions = _options?.Clone() ?? RequestOptions.CreateFromDefaults(_client.ApiClient.Config);
                newOptions.CancellationToken = cancellationToken;

                _currentFeed = await _currentFeed.GetNextPageAsync(newOptions);
                _currentEnumerator = _currentFeed.Content.GetEnumerator();
                return _currentEnumerator.MoveNext();
            }
{'fraction_non_alphanumeric': 0.08879816279663179, 'fraction_numerical': 0.0, 'mean_word_length': 2.280334728033473, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3200965', 'n_tokens_mistral': 993, 'n_tokens_neox': 1002, 'n_words': 268}