| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | // Licensed to the .NET Foundation under one or more agreements.// The .NET Foundation licenses this file to you under the MIT License.// See the LICENSE file in the project root for more information. using System.Linq;using System.Reactive.Disposables;namespace System.Reactive.Linq{    public partial class AsyncObservable    {        public static IAsyncObservable<TSource> Retry<TSource>(this IAsyncObservable<TSource> source)        {            if (source == null)                throw new ArgumentNullException(nameof(source));            return Create(                source,                async static (source, observer) =>                {                    var (sink, inner) = AsyncObserver.Retry(observer, source);                    var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);                    return StableCompositeAsyncDisposable.Create(subscription, inner);                });        }        public static IAsyncObservable<TSource> Retry<TSource>(this IAsyncObservable<TSource> source, int retryCount)        {            if (source == null)                throw new ArgumentNullException(nameof(source));            if (retryCount < 0)                throw new ArgumentOutOfRangeException(nameof(retryCount));            return CreateAsyncObservable<TSource>.From(                source,                retryCount,                static async (source, retryCount, observer) =>                {                    var (sink, inner) = AsyncObserver.Retry(observer, source, retryCount);                    var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);                    return StableCompositeAsyncDisposable.Create(subscription, inner);                });        }    }    public partial class AsyncObserver    {        public static (IAsyncObserver<TSource>, IAsyncDisposable) Retry<TSource>(IAsyncObserver<TSource> observer, IAsyncObservable<TSource> source)        {            if (observer == null)                throw new ArgumentNullException(nameof(observer));            if (source == null)                throw new ArgumentNullException(nameof(source));            return Catch(observer, Repeat(source).GetEnumerator());        }        public static (IAsyncObserver<TSource>, IAsyncDisposable) Retry<TSource>(IAsyncObserver<TSource> observer, IAsyncObservable<TSource> source, int retryCount)        {            if (observer == null)                throw new ArgumentNullException(nameof(observer));            if (source == null)                throw new ArgumentNullException(nameof(source));            if (retryCount < 0)                throw new ArgumentOutOfRangeException(nameof(retryCount));            return Catch(observer, Enumerable.Repeat(source, retryCount).GetEnumerator());        }    }}
 |