<PackageReference Include="System.Reactive" Version="6.0.0-preview.1" />

Catch<TSource, TException>

sealed class Catch<TSource, TException> : Producer<TSource, _<TSource, TException>> where TException : Exception
using System.Reactive.Disposables; using System.Runtime.CompilerServices; using System.Threading; namespace System.Reactive.Linq.ObservableImpl { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1, 1 })] internal sealed class Catch<[System.Runtime.CompilerServices.Nullable(2)] TSource, [System.Runtime.CompilerServices.Nullable(0)] TException> : Producer<TSource, Catch<TSource, TException>._> where TException : Exception { [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] internal sealed class _ : IdentitySink<TSource> { private readonly Func<TException, IObservable<TSource>> _handler; private bool _once; private SerialDisposableValue _subscription; public _(Func<TException, IObservable<TSource>> handler, IObserver<TSource> observer) : base(observer) { _handler = handler; } public override void Run(IObservable<TSource> source) { _subscription.TrySetFirst(ObservableExtensions.SubscribeSafe<TSource>(source, (IObserver<TSource>)this)); } protected override void Dispose(bool disposing) { if (disposing) _subscription.Dispose(); base.Dispose(disposing); } public override void OnError(Exception error) { if (!Volatile.Read(ref _once)) { TException val = error as TException; if (val != null) { IObservable<TSource> source; try { source = _handler(val); } catch (Exception error2) { ForwardOnError(error2); return; } Volatile.Write(ref _once, true); _subscription.Disposable = ObservableExtensions.SubscribeSafe<TSource>(source, (IObserver<TSource>)this); return; } } ForwardOnError(error); } } private readonly IObservable<TSource> _source; private readonly Func<TException, IObservable<TSource>> _handler; public Catch(IObservable<TSource> source, Func<TException, IObservable<TSource>> handler) { _source = source; _handler = handler; } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0, 0 })] protected override _ CreateSink(IObserver<TSource> observer) { return new _(_handler, observer); } protected override void Run([System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0, 0 })] _ sink) { sink.Run(_source); } } }