Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 28 additions & 37 deletions src/Primitives.Shared/Advanced/SubscribeSafeWitness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@ namespace ReactiveUI.Primitives.Advanced;
/// <summary>Static factory methods for <see cref="SubscribeSafeWitness{T}"/> across nullable and value-type call shapes.</summary>
public static class SubscribeSafeWitness
{
/// <summary>Subscribes a nullable reference observer with downstream exception protection.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <summary>Subscribes an observer with downstream exception protection.</summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="observer">The observer to subscribe.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
public static SubscribeSafeWitness<T?> Subscribe<T>(
IObservable<T?> source,
public static SubscribeSafeWitness<T> Subscribe<T>(
IObservable<T> source,
IObserver<T> observer,
params bool[] allowNullable)
where T : class
{
_ = allowNullable;
return SubscribeSafeWitness<T?>.Subscribe(source, (IObserver<T?>)observer);
return SubscribeSafeWitness<T>.Subscribe(source, observer);
}

/// <summary>Subscribes a nullable value observer with downstream exception protection.</summary>
Expand All @@ -37,7 +36,7 @@ public static class SubscribeSafeWitness
/// <param name="observer">The observer to subscribe.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static SubscribeSafeWitness<T?> Subscribe<T>(
IObservable<T?> source,
IObserver<T?> observer,
Expand All @@ -48,24 +47,22 @@ public static class SubscribeSafeWitness
return SubscribeSafeWitness<T?>.Subscribe(source, observer);
}

/// <summary>Subscribes nullable reference callbacks with downstream exception protection.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <summary>Subscribes callbacks with downstream exception protection.</summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="onError">The action to invoke for an error.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
public static SubscribeSafeWitness<T?> Subscribe<T>(
IObservable<T?> source,
public static SubscribeSafeWitness<T> Subscribe<T>(
IObservable<T> source,
Action<T> onNext,
Action<Exception> onError,
params bool[] allowNullable)
where T : class
{
_ = allowNullable;
ArgumentExceptionHelper.ThrowIfNull(onNext);
return SubscribeSafeWitness<T?>.Subscribe(source, Witness.Create<T?>(value => onNext(value!), onError));
return SubscribeSafeWitness<T>.Subscribe(source, onNext, onError);
}

/// <summary>Subscribes nullable value callbacks with downstream exception protection.</summary>
Expand All @@ -75,7 +72,7 @@ public static class SubscribeSafeWitness
/// <param name="onError">The action to invoke for an error.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static SubscribeSafeWitness<T?> Subscribe<T>(
IObservable<T?> source,
Action<T?> onNext,
Expand All @@ -87,28 +84,24 @@ public static class SubscribeSafeWitness
return SubscribeSafeWitness<T?>.Subscribe(source, Witness.Create(onNext, onError));
}

/// <summary>Subscribes nullable reference callbacks with downstream exception protection.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <summary>Subscribes callbacks with downstream exception protection.</summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="onError">The action to invoke for an error.</param>
/// <param name="onCompleted">The action to invoke when the sequence completes.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
public static SubscribeSafeWitness<T?> Subscribe<T>(
IObservable<T?> source,
public static SubscribeSafeWitness<T> Subscribe<T>(
IObservable<T> source,
Action<T> onNext,
Action<Exception> onError,
Action onCompleted,
params bool[] allowNullable)
where T : class
{
_ = allowNullable;
ArgumentExceptionHelper.ThrowIfNull(onNext);
return SubscribeSafeWitness<T?>.Subscribe(
source,
Witness.Create<T?>(value => onNext(value!), onError, onCompleted));
return SubscribeSafeWitness<T>.Subscribe(source, onNext, onError, onCompleted);
}

/// <summary>Subscribes nullable value callbacks with downstream exception protection.</summary>
Expand All @@ -119,7 +112,7 @@ public static class SubscribeSafeWitness
/// <param name="onCompleted">The action to invoke when the sequence completes.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static SubscribeSafeWitness<T?> Subscribe<T>(
IObservable<T?> source,
Action<T?> onNext,
Expand All @@ -132,22 +125,20 @@ public static class SubscribeSafeWitness
return SubscribeSafeWitness<T?>.Subscribe(source, Witness.Create(onNext, onError, onCompleted));
}

/// <summary>Subscribes a nullable reference value callback with downstream exception protection.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <summary>Subscribes a value callback with downstream exception protection.</summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
public static SubscribeSafeWitness<T?> Subscribe<T>(
IObservable<T?> source,
public static SubscribeSafeWitness<T> Subscribe<T>(
IObservable<T> source,
Action<T> onNext,
params bool[] allowNullable)
where T : class
{
_ = allowNullable;
ArgumentExceptionHelper.ThrowIfNull(onNext);
return SubscribeSafeWitness<T?>.Subscribe(source, Witness.Create<T?>(value => onNext(value!)));
return SubscribeSafeWitness<T>.Subscribe(source, onNext);
}

/// <summary>Subscribes a nullable value callback with downstream exception protection.</summary>
Expand All @@ -156,7 +147,7 @@ public static class SubscribeSafeWitness
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static SubscribeSafeWitness<T?> Subscribe<T>(
IObservable<T?> source,
Action<T?> onNext,
Expand All @@ -173,7 +164,7 @@ public static class SubscribeSafeWitness
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="allowValueType">Reserved for value-type overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static SubscribeSafeWitness<T> Subscribe<T>(
IObservable<T> source,
Action<T> onNext,
Expand All @@ -190,7 +181,7 @@ public static SubscribeSafeWitness<T> Subscribe<T>(
/// <param name="observer">The observer to subscribe.</param>
/// <param name="allowValueType">Reserved for value-type overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static SubscribeSafeWitness<T> Subscribe<T>(
IObservable<T> source,
IObserver<T> observer,
Expand All @@ -208,7 +199,7 @@ public static SubscribeSafeWitness<T> Subscribe<T>(
/// <param name="onError">The action to invoke for an error.</param>
/// <param name="allowValueType">Reserved for value-type overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static SubscribeSafeWitness<T> Subscribe<T>(
IObservable<T> source,
Action<T> onNext,
Expand All @@ -228,7 +219,7 @@ public static SubscribeSafeWitness<T> Subscribe<T>(
/// <param name="onCompleted">The action to invoke when the sequence completes.</param>
/// <param name="allowValueType">Reserved for value-type overload resolution.</param>
/// <returns>The witness subscription.</returns>
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static SubscribeSafeWitness<T> Subscribe<T>(
IObservable<T> source,
Action<T> onNext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace ReactiveUI.Primitives;
/// <summary>The System.Reactive-named SubscribeSafe overloads, which isolate observer faults from the source.</summary>
public static partial class LinqExtensions
{
/// <summary>Subscribes a nullable reference observer with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <summary>Subscribes an observer with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="observer">The observer to subscribe.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
Expand All @@ -24,10 +24,9 @@ public static partial class LinqExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
IObservable<T> source,
IObserver<T> observer,
params bool[] allowNullable)
where T : class =>
params bool[] allowNullable) =>
SubscribeSafeWitness.Subscribe(source, observer, allowNullable);

/// <summary>Subscribes a nullable value observer with downstream exception protection from static-call syntax.</summary>
Expand All @@ -38,16 +37,16 @@ public static IDisposable SubscribeSafe<T>(
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="observer"/> is <see langword="null"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
IObserver<T?> observer,
params bool[] allowNullable)
where T : struct =>
SubscribeSafeWitness.Subscribe(source, observer, allowNullable);

/// <summary>Subscribes nullable reference callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <summary>Subscribes callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="onError">The action to invoke for an error.</param>
Expand All @@ -57,11 +56,10 @@ public static IDisposable SubscribeSafe<T>(
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
IObservable<T> source,
Action<T> onNext,
Action<Exception> onError,
params bool[] allowNullable)
where T : class =>
params bool[] allowNullable) =>
SubscribeSafeWitness.Subscribe(source, onNext, onError, allowNullable);

/// <summary>Subscribes nullable value callbacks with downstream exception protection from static-call syntax.</summary>
Expand All @@ -73,7 +71,7 @@ public static IDisposable SubscribeSafe<T>(
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
Action<T?> onNext,
Expand All @@ -82,8 +80,8 @@ public static IDisposable SubscribeSafe<T>(
where T : struct =>
SubscribeSafeWitness.Subscribe(source, onNext, onError, allowNullable);

/// <summary>Subscribes nullable reference callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <summary>Subscribes callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="onError">The action to invoke for an error.</param>
Expand All @@ -94,12 +92,11 @@ public static IDisposable SubscribeSafe<T>(
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
IObservable<T> source,
Action<T> onNext,
Action<Exception> onError,
Action onCompleted,
params bool[] allowNullable)
where T : class =>
params bool[] allowNullable) =>
SubscribeSafeWitness.Subscribe(source, onNext, onError, onCompleted, allowNullable);

/// <summary>Subscribes nullable value callbacks with downstream exception protection from static-call syntax.</summary>
Expand All @@ -112,7 +109,7 @@ public static IDisposable SubscribeSafe<T>(
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
Action<T?> onNext,
Expand All @@ -122,8 +119,8 @@ public static IDisposable SubscribeSafe<T>(
where T : struct =>
SubscribeSafeWitness.Subscribe(source, onNext, onError, onCompleted, allowNullable);

/// <summary>Subscribes a nullable reference value callback with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <summary>Subscribes a value callback with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
Expand All @@ -133,10 +130,9 @@ public static IDisposable SubscribeSafe<T>(
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
IObservable<T> source,
Action<T> onNext,
params bool[] allowNullable)
where T : class =>
params bool[] allowNullable) =>
SubscribeSafeWitness.Subscribe(source, onNext, allowNullable);

/// <summary>Subscribes a nullable value callback with downstream exception protection from static-call syntax.</summary>
Expand All @@ -148,7 +144,7 @@ public static IDisposable SubscribeSafe<T>(
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
/// <remarks>With no error handler, a source error is rethrown to the caller of the source's <c>OnError</c>.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
Action<T?> onNext,
Expand All @@ -165,7 +161,7 @@ public static IDisposable SubscribeSafe<T>(
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
/// <remarks>With no error handler, a source error is rethrown to the caller of the source's <c>OnError</c>.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static IDisposable SubscribeSafe<T>(
IObservable<T> source,
Action<T> onNext,
Expand All @@ -181,7 +177,7 @@ public static IDisposable SubscribeSafe<T>(
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="observer"/> is <see langword="null"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static IDisposable SubscribeSafe<T>(
IObservable<T> source,
IObserver<T> observer,
Expand All @@ -198,7 +194,7 @@ public static IDisposable SubscribeSafe<T>(
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static IDisposable SubscribeSafe<T>(
IObservable<T> source,
Action<T> onNext,
Expand All @@ -217,7 +213,7 @@ public static IDisposable SubscribeSafe<T>(
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(1)]
[OverloadResolutionPriority(2)]
public static IDisposable SubscribeSafe<T>(
IObservable<T> source,
Action<T> onNext,
Expand Down
Loading
Loading