コード例 #1
0
ファイル: Factory.cs プロジェクト: stazz/AsyncEnumeration
 internal static SequentialEnumeratorCurrentInfo <T> GetInstance <T>(
     MoveNextAsyncDelegate <T> moveNext,
     EnumerationEndedDelegate dispose
     )
 {
     return((SequentialEnumeratorCurrentInfo <T>)GetFactory(typeof(T))?.Invoke(moveNext, dispose) ?? new SequentialEnumeratorCurrentInfoWithObject <T>(moveNext, dispose));
 }
コード例 #2
0
ファイル: Factory.cs プロジェクト: stazz/AsyncEnumeration
 /// <summary>
 /// Initializes a new <see cref="SequentialEnumerationStartInfo{T}"/> with given callbacks.
 /// </summary>
 /// <param name="moveNext">The callback to fetch next item.</param>
 /// <param name="dispose">The optional callback to dispose enumerator. May be <c>null</c>.</param>
 /// <remarks>
 /// If <paramref name="moveNext"/> is <c>null</c>, then enumeration ends immediately.
 /// </remarks>
 /// <seealso cref="AsyncEnumerationFactory.CreateSequentialStartInfo"/>
 public SequentialEnumerationStartInfo(
     MoveNextAsyncDelegate <T> moveNext,
     EnumerationEndedDelegate dispose
     )
 {
     this.MoveNext = moveNext;
     this.Dispose  = dispose;
 }
コード例 #3
0
ファイル: Factory.cs プロジェクト: stazz/AsyncEnumeration
 /// <summary>
 ///  Helper method to invoke constructor of <see cref="WrappingEnumerationStartInfo{T}"/> without explicitly specifying generic type arguments.
 /// </summary>
 /// <typeparam name="T">The type of items being enumerated.</typeparam>
 /// <param name="waitForNext">The callback that will be used by <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/>.</param>
 /// <param name="tryGetNext">The callback that will be used by <see cref="IAsyncEnumerator{T}.TryGetNext"/>.</param>
 /// <param name="dispose">The optional callback that will be used by <see cref="IAsyncDisposable.DisposeAsync"/>.</param>
 /// <returns>A new instance of <see cref="WrappingEnumerationStartInfo{T}"/>.</returns>
 /// <exception cref="ArgumentNullException">If either of <paramref name="waitForNext"/> or <paramref name="tryGetNext"/> is <c>null</c>.</exception>
 /// <seealso cref="WrappingEnumerationStartInfo{T}"/>
 public static WrappingEnumerationStartInfo <T> CreateWrappingStartInfo <T>(
     WaitForNextDelegate waitForNext,
     TryGetNextDelegate <T> tryGetNext,
     EnumerationEndedDelegate dispose
     )
 {
     return(new WrappingEnumerationStartInfo <T>(waitForNext, tryGetNext, dispose));
 }
コード例 #4
0
ファイル: Factory.cs プロジェクト: stazz/AsyncEnumeration
 /// <summary>
 /// Creates a new instance of <see cref="WrappingEnumerationStartInfo{T}"/>.
 /// </summary>
 /// <param name="waitForNext">The callback that will be used by <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/>.</param>
 /// <param name="tryGetNext">The callback that will be used by <see cref="IAsyncEnumerator{T}.TryGetNext"/>.</param>
 /// <param name="dispose">The optional callback that will be used by <see cref="IAsyncDisposable.DisposeAsync"/>.</param>
 /// <exception cref="ArgumentNullException">If either of <paramref name="waitForNext"/> or <paramref name="tryGetNext"/> is <c>null</c>.</exception>
 public WrappingEnumerationStartInfo(
     WaitForNextDelegate waitForNext,
     TryGetNextDelegate <T> tryGetNext,
     EnumerationEndedDelegate dispose
     )
 {
     this.WaitForNext = waitForNext;
     this.TryGetNext  = tryGetNext;
     this.Dispose     = dispose;
 }
コード例 #5
0
 internal static void InitVars <T>(
     WaitForNextDelegate waitForNext,
     TryGetNextDelegate <T> tryGetNext,
     EnumerationEndedDelegate dispose,
     out WaitForNextDelegate fieldWaitForNext,
     out TryGetNextDelegate <T> fieldTryGetNext,
     out EnumerationEndedDelegate fieldDispose
     )
 {
     fieldWaitForNext = ArgumentValidator.ValidateNotNull(nameof(waitForNext), waitForNext);
     fieldTryGetNext  = ArgumentValidator.ValidateNotNull(nameof(tryGetNext), tryGetNext);
     fieldDispose     = dispose ?? (() => TaskUtils.CompletedTask);
 }
コード例 #6
0
ファイル: Factory.cs プロジェクト: stazz/AsyncEnumeration
        /// <summary>
        /// Helper method to create <see cref="WrappingEnumerationStartInfo{T}"/> which will return <c>true</c> only once for its <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/> method, and the rest of the items are returned via <see cref="IAsyncEnumerator{T}.TryGetNext(out Boolean)"/> method.
        /// </summary>
        /// <typeparam name="T">The type of items being enumerated.</typeparam>
        /// <param name="tryGetNext">The callback to get next item.</param>
        /// <param name="dispose">The optional disposing callback.</param>
        /// <returns></returns>
        public static WrappingEnumerationStartInfo <T> CreateSynchronousWrappingStartInfo <T>(
            TryGetNextDelegate <T> tryGetNext,
            EnumerationEndedDelegate dispose = null
            )
        {
            const Int32 INITIAL = 0;
            const Int32 STARTED = 1;
            var         state   = INITIAL;

            return(CreateWrappingStartInfo(
                       () =>
            {
                return TaskUtils.TaskFromBoolean(Interlocked.CompareExchange(ref state, STARTED, INITIAL) == INITIAL);
            },
                       tryGetNext,
                       dispose
                       ));
        }
コード例 #7
0
ファイル: Factory.cs プロジェクト: stazz/AsyncEnumeration
 /// <summary>
 /// Creates a new instance of <see cref="IAsyncEnumerator{T}"/> which fetches one item at a time using given callback.
 /// </summary>
 /// <typeparam name="T">The type of items being enumerated.</typeparam>
 /// <param name="moveNext">The callback for potentially asynchronously fetching next item.</param>
 /// <param name="dispose">The callback to dispose enumerator.</param>
 /// <returns>A new instance of <see cref="IAsyncEnumerator{T}"/> which behaves like <paramref name="moveNext"/> and <paramref name="dispose"/> specify.</returns>
 /// <remarks>
 /// The returned <see cref="IAsyncEnumerator{T}"/> will have guard code to prevent concurrent invocation.
 /// </remarks>
 public static IAsyncEnumerator <T> CreateSequentialEnumerator <T>(
     MoveNextAsyncDelegate <T> moveNext,
     EnumerationEndedDelegate dispose
     ) => new AsyncEnumerator <T>(SequentialCurrentInfoFactory.GetInstance(moveNext, dispose));
コード例 #8
0
ファイル: Factory.cs プロジェクト: stazz/AsyncEnumeration
 /// <summary>
 /// Helper method to invoke constructor of <see cref="SequentialEnumerationStartInfo{T}"/> without explicitly specifying generic type arguments.
 /// </summary>
 /// <typeparam name="T">The type of items being enumerated.</typeparam>
 /// <param name="moveNext">The callback for potentially asynchronously fetching next item.</param>
 /// <param name="dispose">The callback to dispose enumerator.</param>
 /// <returns>A new <see cref="SequentialEnumerationStartInfo{T}"/>.</returns>
 /// <seealso cref="SequentialEnumerationStartInfo{T}.SequentialEnumerationStartInfo(MoveNextAsyncDelegate{T}, EnumerationEndedDelegate)"/>
 public static SequentialEnumerationStartInfo <T> CreateSequentialStartInfo <T>(
     MoveNextAsyncDelegate <T> moveNext,
     EnumerationEndedDelegate dispose
     ) => new SequentialEnumerationStartInfo <T>(moveNext, dispose);