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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1147,8 +1147,9 @@ share one subscription instead of starting the work over each time.
| `SubscribePrimitives()` and its 4 overloads | Gives you the same five methods under a name that cannot clash with another library. | `Subscribe` |
| `SubscribeSafe(observer)` | Subscribes and keeps your observer's exceptions away from the producer. | `SubscribeSafe` |
| `SubscribeSafePrimitives(observer)` | Gives you the same method under a name that cannot clash. | `SubscribeSafe` |
| `SubscribeSafe(onNext, onError)`, `SubscribeSafe(onNext, onError, onCompleted)`, `SubscribeSafe(onError)`, `SubscribeSafe(onError, onCompleted)` | Callback forms of `SubscribeSafe`. | `SubscribeSafe` |
| `LinqExtensions.SubscribeSafe(source, ...)`, 14 static overloads | Lets a nullable source pick one overload without ambiguity; the `params` array is a marker and is never read. | `SubscribeSafe` |
| `SubscribeSafe(onNext)`, `SubscribeSafe(onNext, onError)`, `SubscribeSafe(onNext, onError, onCompleted)` | Callback forms of `SubscribeSafe`. A lone delegate is `onNext`. With no error handler, a source error is rethrown. | `SubscribeSafe` |
| `SubscribeSafeErrors(onError)`, `SubscribeSafeErrors(onError, onCompleted)` | Subscribes with error and completion callbacks only. Values are ignored. | None |
| `LinqExtensions.SubscribeSafe(source, ...)`, 12 static overloads, and `LinqExtensions.SubscribeSafeErrors(source, ...)`, 6 static overloads | Lets a nullable source pick one overload without ambiguity; the `params` array is a marker and is never read. | `SubscribeSafe` |
| `IObserver<T>.FastForEach(source)` | Pushes a whole collection into an observer and indexes arrays and lists directly. | - |
| `ObserveOn(sequencer)` | Delivers notifications to subscribers on the sequencer you name. | `ObserveOn` |
| `WitnessOn(sequencer)` | Another name for `ObserveOn`. | `ObserveOn` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,88 +131,61 @@ public static IDisposable SubscribeSafe<T>(
return SubscribeSafeCore(source, Witness.Create(onNext, onError, onCompleted));
}

/// <summary>Subscribes nullable reference terminal callbacks with downstream exception protection from static-call syntax.</summary>
/// <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>
/// <param name="source">The source sequence.</param>
/// <param name="onError">The action to invoke for an error.</param>
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>A disposable that cancels the subscription.</returns>
/// <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>
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
Action<Exception> onError,
Action<T> onNext,
params bool[] allowNullable)
where T : class
{
_ = allowNullable;
return SubscribeSafeCore(source, Witness.Create<T?>(static _ => { }, onError));
return SubscribeSafeCore(source, Witness.Create<T?>(value => onNext(value!)));
}

/// <summary>Subscribes nullable value terminal callbacks with downstream exception protection from static-call syntax.</summary>
/// <summary>Subscribes a nullable value callback with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onError">The action to invoke for an error.</param>
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>A disposable that cancels the subscription.</returns>
/// <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>
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Design",
"SST2318:Members should not have identical bodies",
Justification = "The class-constrained and struct-constrained overloads cannot forward to one another.")]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
Action<Exception> onError,
Action<T?> onNext,
params bool[] allowNullable)
where T : struct
{
_ = allowNullable;
return SubscribeSafeCore(source, Witness.Create<T?>(static _ => { }, onError));
}

/// <summary>Subscribes nullable reference terminal callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <param name="source">The source sequence.</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>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
Action<Exception> onError,
Action onCompleted,
params bool[] allowNullable)
where T : class
{
_ = allowNullable;
return SubscribeSafeCore(source, Witness.Create<T?>(static _ => { }, onError, onCompleted));
return SubscribeSafeCore(source, Witness.Create(onNext));
}

/// <summary>Subscribes nullable value terminal callbacks with downstream exception protection from static-call syntax.</summary>
/// <summary>Subscribes non-nullable value callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable value type.</typeparam>
/// <param name="source">The source sequence.</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>
/// <param name="onNext">The action to invoke for each value.</param>
/// <param name="allowValueType">Reserved for value-type overload resolution.</param>
/// <returns>A disposable that cancels the subscription.</returns>
/// <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>
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Design",
"SST2318:Members should not have identical bodies",
Justification = "The class-constrained and struct-constrained overloads cannot forward to one another.")]
public static IDisposable SubscribeSafe<T>(
IObservable<T?> source,
Action<Exception> onError,
Action onCompleted,
params bool[] allowNullable)
IObservable<T> source,
Action<T> onNext,
params byte[] allowValueType)
where T : struct
{
_ = allowNullable;
return SubscribeSafeCore(source, Witness.Create<T?>(static _ => { }, onError, onCompleted));
_ = allowValueType;
return SubscribeSafeCore(source, Witness.Create(onNext));
}

/// <summary>Subscribes a non-nullable value observer with downstream exception protection from static-call syntax.</summary>
Expand Down Expand Up @@ -275,15 +248,99 @@ public static IDisposable SubscribeSafe<T>(
return SubscribeSafeCore(source, Witness.Create(onNext, onError, onCompleted));
}

/// <summary>Subscribes non-nullable value terminal callbacks with downstream exception protection from static-call syntax.</summary>
/// <summary>Subscribes nullable reference error callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onError">The action to invoke for an error.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
public static IDisposable SubscribeSafeErrors<T>(
IObservable<T?> source,
Action<Exception> onError,
params bool[] allowNullable)
where T : class
{
_ = allowNullable;
return SubscribeSafeCore(source, Witness.Create<T?>(static _ => { }, onError));
}

/// <summary>Subscribes nullable value error callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onError">The action to invoke for an error.</param>
/// <param name="allowNullable">Reserved for nullable overload resolution.</param>
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Design",
"SST2318:Members should not have identical bodies",
Justification = "The class-constrained and struct-constrained overloads cannot forward to one another.")]
public static IDisposable SubscribeSafeErrors<T>(
IObservable<T?> source,
Action<Exception> onError,
params bool[] allowNullable)
where T : struct
{
_ = allowNullable;
return SubscribeSafeCore(source, Witness.Create<T?>(static _ => { }, onError));
}

/// <summary>Subscribes nullable reference error and completion callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable reference value type.</typeparam>
/// <param name="source">The source sequence.</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>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
public static IDisposable SubscribeSafeErrors<T>(
IObservable<T?> source,
Action<Exception> onError,
Action onCompleted,
params bool[] allowNullable)
where T : class
{
_ = allowNullable;
return SubscribeSafeCore(source, Witness.Create<T?>(static _ => { }, onError, onCompleted));
}

/// <summary>Subscribes nullable value error and completion callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable value type.</typeparam>
/// <param name="source">The source sequence.</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>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Design",
"SST2318:Members should not have identical bodies",
Justification = "The class-constrained and struct-constrained overloads cannot forward to one another.")]
public static IDisposable SubscribeSafeErrors<T>(
IObservable<T?> source,
Action<Exception> onError,
Action onCompleted,
params bool[] allowNullable)
where T : struct
{
_ = allowNullable;
return SubscribeSafeCore(source, Witness.Create<T?>(static _ => { }, onError, onCompleted));
}

/// <summary>Subscribes non-nullable value error callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onError">The action to invoke for an error.</param>
/// <param name="allowValueType">Reserved for value-type overload resolution.</param>
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
public static IDisposable SubscribeSafe<T>(
public static IDisposable SubscribeSafeErrors<T>(
IObservable<T> source,
Action<Exception> onError,
params byte[] allowValueType)
Expand All @@ -293,7 +350,7 @@ public static IDisposable SubscribeSafe<T>(
return SubscribeSafeCore(source, Witness.Create<T>(static _ => { }, onError));
}

/// <summary>Subscribes non-nullable value terminal callbacks with downstream exception protection from static-call syntax.</summary>
/// <summary>Subscribes non-nullable value error and completion callbacks with downstream exception protection from static-call syntax.</summary>
/// <typeparam name="T">The non-nullable value type.</typeparam>
/// <param name="source">The source sequence.</param>
/// <param name="onError">The action to invoke for an error.</param>
Expand All @@ -302,7 +359,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>
[System.Runtime.CompilerServices.OverloadResolutionPriority(1)]
public static IDisposable SubscribeSafe<T>(
public static IDisposable SubscribeSafeErrors<T>(
IObservable<T> source,
Action<Exception> onError,
Action onCompleted,
Expand Down
17 changes: 13 additions & 4 deletions src/Primitives.Shared/SignalOperatorParityMixins.RxNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,30 @@ public IDisposable SubscribeSafe(Action<T> onNext, Action<Exception> onError) =>
public IDisposable SubscribeSafe(Action<T> onNext, Action<Exception> onError, Action onCompleted) =>
SubscribeSafeCore(source, Witness.Create(onNext, onError, onCompleted));

/// <summary>Subscribes terminal callbacks with downstream exception protection.</summary>
/// <summary>Subscribes a value callback with downstream exception protection.</summary>
/// <param name="onNext">The action to invoke for each value.</param>
/// <returns>A disposable that cancels the subscription.</returns>
/// <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)]
public IDisposable SubscribeSafe(Action<T> onNext) =>
SubscribeSafeCore(source, Witness.Create(onNext));

/// <summary>Subscribes error callbacks with downstream exception protection.</summary>
/// <param name="onError">The action to invoke for an error.</param>
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IDisposable SubscribeSafe(Action<Exception> onError) =>
public IDisposable SubscribeSafeErrors(Action<Exception> onError) =>
SubscribeSafeCore(source, Witness.Create<T>(static _ => { }, onError));

/// <summary>Subscribes terminal callbacks with downstream exception protection.</summary>
/// <summary>Subscribes error and completion callbacks with downstream exception protection.</summary>
/// <param name="onError">The action to invoke for an error.</param>
/// <param name="onCompleted">The action to invoke when the sequence completes.</param>
/// <returns>A disposable that cancels the subscription.</returns>
/// <exception cref="ArgumentNullException">A required argument is <see langword="null"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IDisposable SubscribeSafe(Action<Exception> onError, Action onCompleted) =>
public IDisposable SubscribeSafeErrors(Action<Exception> onError, Action onCompleted) =>
SubscribeSafeCore(source, Witness.Create<T>(static _ => { }, onError, onCompleted));

/// <summary>Invokes an action for each value while preserving the sequence.</summary>
Expand Down
Loading
Loading