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

#if netfx
using BoolResultTask = System.Threading.Tasks.Task<bool>;
#else
using BoolResultTask = System.Threading.Tasks.ValueTask<bool>;
#endif

namespace Chloe.Query.Internals
{
    internal class DataReaderEnumerator : IEnumerator<IDataReader>, Chloe.Collections.Generic.IAsyncEnumerator<IDataReader>
    {
        bool _disposed;
        bool _hasFinished;
        Func<bool, Task<IDataReader>> _dataReaderCreator;
        IDataReader _reader;
        IDataReader _current;

        public DataReaderEnumerator(Func<bool, Task<IDataReader>> dataReaderCreator)
        {
            this._dataReaderCreator = dataReaderCreator;
        }

        public IDataReader Current { get { return this._current; } }

        object IEnumerator.Current { get { return this._current; } }

        public bool MoveNext()
        {
            return this.MoveNext(false).GetResult();
        }

        BoolResultTask Chloe.Collections.Generic.IAsyncEnumerator<IDataReader>.MoveNext()
        {
            return this.MoveNext(true);
        }

        public BoolResultTask MoveNextAsync()
        {
            return this.MoveNext(true);
        }

        async BoolResultTask MoveNext(bool @async)
        {
            if (this._hasFinished || this._disposed)
                return false;

            if (this._reader == null)
            {
                this._reader = await this._dataReaderCreator(@async);
            }

            bool readResult = @async ? await this._reader.Read(@async) : this._reader.Read();
            if (readResult)
            {
                this._current = this._reader;
                return true;
            }
            else
            {
                this._reader.Close();
                this._current = default;
                this._hasFinished = true;
                return false;
            }
        }

        public void Dispose()
        {
            if (this._disposed)
                return;

            if (this._reader != null)
            {
                if (!this._reader.IsClosed)
                    this._reader.Close();
                this._reader.Dispose();
                this._reader = null;
            }

            this._hasFinished = true;
            this._current = default;
            this._disposed = true;
        }<commit_msg>Code fixes.<commit_after>﻿using Chloe.Threading.Tasks;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;

#if netfx
using BoolResultTask = System.Threading.Tasks.Task<bool>;
#else
using BoolResultTask = System.Threading.Tasks.ValueTask<bool>;
#endif

namespace Chloe.Query.Internals
{
    internal class DataReaderEnumerator : IEnumerator<IDataReader>, Chloe.Collections.Generic.IAsyncEnumerator<IDataReader>
    {
        bool _disposed;
        bool _hasFinished;
        Func<bool, Task<IDataReader>> _dataReaderCreator;
        IDataReader _reader;
        IDataReader _current;

        public DataReaderEnumerator(Func<bool, Task<IDataReader>> dataReaderCreator)
        {
            this._dataReaderCreator = dataReaderCreator;
        }

        public IDataReader Current { get { return this._current; } }

        object IEnumerator.Current { get { return this._current; } }

        public bool MoveNext()
        {
            return this.MoveNext(false).GetResult();
        }

        BoolResultTask Chloe.Collections.Generic.IAsyncEnumerator<IDataReader>.MoveNext()
        {
            return this.MoveNext(true);
        }

        public BoolResultTask MoveNextAsync()
        {
            return this.MoveNext(true);
        }

        async BoolResultTask MoveNext(bool @async)
        {
            if (this._hasFinished || this._disposed)
                return false;

            if (this._reader == null)
            {
                this._reader = await this._dataReaderCreator(@async);
            }

            bool readResult = await this._reader.Read(@async);
            if (readResult)
            {
                this._current = this._reader;
                return true;
            }
            else
            {
                this._reader.Close();
                this._current = default;
                this._hasFinished = true;
                return false;
            }
        }

        public void Dispose()
        {
            if (this._disposed)
                return;

            if (this._reader != null)
            {
                if (!this._reader.IsClosed)
                    this._reader.Close();
                this._reader.Dispose();
                this._reader = null;
            }

            this._hasFinished = true;
            this._current = default;
            this._disposed = true;
        }
{'fraction_non_alphanumeric': 0.08831274053068665, 'fraction_numerical': 0.0, 'mean_word_length': 1.6591276252019387, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6882165', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1262, 'n_words': 253}