dotnet / dotnet/reactive

[Feature Request] Expose `HalfSerializer` for public use?

Open
#2,032 0 comments 1 reaction 0 assignees View on GitHub
[area] Rx
Dominant language
C#
Stars
7.2k
Forks
798
PR merge metrics
No merged PRs in 30d

Description

I recently had a case where I was building an observable wrapper over a module where `OnNext` would be guaranteed to be called serially, while `OnCompleted/OnError` may be called concurrently.

Since I knew `OnCompleted/OnError` would not be called frequently, I used a `SpinLock` where the `OnNext` path would use `TryEnter` (non-blocking) and the `OnComplete/OnError` would use `Enter` (spin-waiting), and this works fine given my situation.

I later went digging through the Rx.NET source and found this absolute gem by the name of [`HalfSerializer`](https://github.com/dotnet/reactive/blob/main/Rx.NET/Source/src/System.Reactive/Internal/HalfSerializer.cs) which is _exactly_ what I needed for my use case! The implementation is very elegant and completely non-blocking. 🤩

Would it be possible to expose a thin wrapper around it that allows me to pass in an `IObserver` rather than `ISink`?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.