Summary

Class:AsyncEnumeration.Implementation.Enumerable.AsyncEnumeratorWrapperInitializer
Assembly:AsyncEnumeration.Implementation.Enumerable
File(s):/repo-dir/contents/Source/Code/AsyncEnumeration.Implementation.Enumerable/Wrapper.cs
Covered lines:4
Uncovered lines:0
Coverable lines:4
Total lines:108
Line coverage:100%
Branch coverage:100%
Tag:7d9974899246b95481b7aa9cd3a1462ae2a67c91

Coverage History

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
InitVars(...)401%1%

File(s)

/repo-dir/contents/Source/Code/AsyncEnumeration.Implementation.Enumerable/Wrapper.cs

#LineLine coverage
 1/*
 2 * Copyright 2018 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using AsyncEnumeration.Abstractions;
 19using System;
 20using System.Collections.Generic;
 21using System.Text;
 22using System.Threading.Tasks;
 23using UtilPack;
 24
 25namespace AsyncEnumeration.Implementation.Enumerable
 26{
 27
 28   internal sealed class StatefulAsyncEnumerableWrapper<T> : IAsyncEnumerable<T>
 29   {
 30      private readonly Func<WrappingEnumerationStartInfo<T>> _factory;
 31
 32      public StatefulAsyncEnumerableWrapper(
 33         Func<WrappingEnumerationStartInfo<T>> startInfoFactory,
 34         IAsyncProvider asyncProvider
 35      )
 36      {
 37         this._factory = ArgumentValidator.ValidateNotNull( nameof( startInfoFactory ), startInfoFactory );
 38         this.AsyncProvider = ArgumentValidator.ValidateNotNull( nameof( asyncProvider ), asyncProvider );
 39      }
 40
 41      public IAsyncProvider AsyncProvider { get; }
 42
 43      public IAsyncEnumerator<T> GetAsyncEnumerator()
 44      {
 45         return new AsyncEnumeratorWrapper<T>( this._factory() );
 46      }
 47   }
 48
 49   internal sealed class StatelessAsyncEnumerableWrapper<T> : IAsyncEnumerable<T>
 50   {
 51      private readonly AsyncEnumeratorWrapper<T> _enumerator;
 52
 53      public StatelessAsyncEnumerableWrapper(
 54         WrappingEnumerationStartInfo<T> startInfo,
 55         IAsyncProvider asyncProvider
 56         )
 57      {
 58         this._enumerator = new AsyncEnumeratorWrapper<T>( startInfo );
 59         this.AsyncProvider = ArgumentValidator.ValidateNotNull( nameof( asyncProvider ), asyncProvider );
 60      }
 61
 62      public IAsyncProvider AsyncProvider { get; }
 63
 64      public IAsyncEnumerator<T> GetAsyncEnumerator()
 65      {
 66         return this._enumerator;
 67      }
 68   }
 69
 70   internal sealed class AsyncEnumeratorWrapper<T> : IAsyncEnumerator<T>
 71   {
 72      private readonly WaitForNextDelegate _waitForNext;
 73      private readonly TryGetNextDelegate<T> _tryGetNext;
 74      private readonly EnumerationEndedDelegate _dispose;
 75
 76      public AsyncEnumeratorWrapper(
 77         WrappingEnumerationStartInfo<T> startInfo
 78         )
 79      {
 80         AsyncEnumeratorWrapperInitializer.InitVars( startInfo.WaitForNext, startInfo.TryGetNext, startInfo.Dispose, out
 81      }
 82
 83      public Task<Boolean> WaitForNextAsync() => this._waitForNext();
 84
 85      public T TryGetNext( out Boolean success ) => this._tryGetNext( out success );
 86
 87      public Task DisposeAsync() => this._dispose();
 88
 89
 90   }
 91
 92   internal static class AsyncEnumeratorWrapperInitializer
 93   {
 94      internal static void InitVars<T>(
 95         WaitForNextDelegate waitForNext,
 96         TryGetNextDelegate<T> tryGetNext,
 97         EnumerationEndedDelegate dispose,
 98         out WaitForNextDelegate fieldWaitForNext,
 99         out TryGetNextDelegate<T> fieldTryGetNext,
 100         out EnumerationEndedDelegate fieldDispose
 101         )
 102      {
 21103         fieldWaitForNext = ArgumentValidator.ValidateNotNull( nameof( waitForNext ), waitForNext );
 21104         fieldTryGetNext = ArgumentValidator.ValidateNotNull( nameof( tryGetNext ), tryGetNext );
 41105         fieldDispose = dispose ?? ( () => TaskUtils.CompletedTask );
 21106      }
 107   }
 108}