/// <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)); }
/// <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; }
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); }
/// <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 )); }