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

HalfSerializer

static class HalfSerializer
Utility methods for dealing with serializing OnXXX signals for an IObserver where concurrent OnNext is still not allowed but concurrent OnError/OnCompleted may happen. This serialization case is generally lower overhead than a full SerializedObserver wrapper and doesn't need allocation.
public static void ForwardOnCompleted<T>(ISink<T> sink, ref int wip, ref Exception error)

Signals OnCompleted on the observer. If there is a concurrent OnNext emission happening, the error field will host a special terminal exception signal to be picked up by ForwardOnNext<T> once it finishes with OnNext and signal the OnCompleted as well. This method can be called concurrently with itself and the other methods of this helper class but only one terminal signal may actually win.

public static void ForwardOnError<T>(ISink<T> sink, Exception ex, ref int wip, ref Exception error)

Signals the given exception to the observer. If there is a concurrent OnNext emission is happening, saves the exception into the given field otherwise to be picked up by ForwardOnNext<T>. This method can be called concurrently with itself and the other methods of this helper class but only one terminal signal may actually win.

public static void ForwardOnNext<T>(ISink<T> sink, T item, ref int wip, ref Exception error)

Signals the given item to the observer in a serialized fashion allowing a concurrent OnError or OnCompleted emission to be delayed until the observer.OnNext returns. Do not call OnNext from multiple threads as it may lead to ignored items. Use a full SerializedObserver wrapper for merging multiple sequences.