
R3 Reactive Extensions
FreeModern reactive programming for C# with R3.
Free · Opens the source repo
What R3 Reactive Extensions does
R3 is a modern reimplementation of Reactive Extensions designed to improve the reactive programming experience in C#. Built by Cysharp, R3 addresses key issues found in the traditional System.Reactive (Rx.NET) framework, such as subscription management and error handling. With R3, developers can leverage a LINQ-over-events programming model while benefiting from a more robust core that simplifies the handling of event streams, UI inputs, and asynchronous operations.
One of the standout features of R3 is its handling of errors in reactive streams. Unlike Rx.NET, where a single error can terminate a subscription, R3 introduces the OnErrorResume method, allowing subscriptions to remain active even when errors occur. This is particularly beneficial for long-lived event streams, such as those found in UI applications, where maintaining a stable connection is crucial. Additionally, R3's design simplifies the concurrency model by replacing the complex IScheduler with .NET 8's TimeProvider and a new FrameProvider, leading to improved performance and reduced memory overhead.
R3 is particularly useful for developers working on applications that require event-driven architectures, such as MVVM applications, where state management is key. It provides operators like debounce, throttle, and merge, which are essential for managing event streams effectively. Furthermore, R3 facilitates seamless integration with asynchronous programming patterns, bridging the gap between push-based and pull-based paradigms through constructs like AwaitOperation and IAsyncEnumerable.
This skill is ideal for developers looking to migrate from System.Reactive or those who want to implement reactive programming in their C# applications without the pitfalls of previous implementations. With comprehensive documentation and reference materials provided, R3 empowers developers to create responsive and resilient applications with ease.
When to use it
Use this skill when building event-driven applications, especially those requiring robust error handling and asynchronous integration.
When not to use it
This skill is not suited for request/response I/O or scenarios requiring backpressure management, where other frameworks like Akka.NET Streams would be more appropriate.
What you can build with it
Building Responsive UIs
Utilize R3 to manage UI state and inputs efficiently in MVVM applications, ensuring a smooth user experience.
Handling Websocket Messages
Leverage R3 to compose and manage streams of data from websocket connections, maintaining responsiveness even under error conditions.
Migrating from Rx.NET
Transition existing Rx.NET applications to R3 to take advantage of improved error handling and subscription management.
How to install R3 Reactive Extensions
View source1. Install with the skills CLI
npx skills add aaronontheweb/dotnet-skills/r3-reactive-extensions --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by aarononthewebR3: Modern Reactive Extensions for .NET
R3 is Cysharp's ground-up reimplementation of Reactive
Extensions — "the new future of dotnet/reactive and UniRx." It keeps the LINQ-over-events
programming model but rebuilds the core types, error contract, and scheduler to fix
long-standing problems in System.Reactive (Rx.NET). Use this skill when composing event
streams, UI input, timers, or push-based pipelines in C#.
Canonical sources (link to these from code and docs):
- Repository: https://github.com/Cysharp/R3
- README (full operator reference): https://github.com/Cysharp/R3/blob/main/README.md
- Author's design rationale: https://neuecc.medium.com/r3-a-new-modern-reimplementation-of-reactive-extensions-for-c-cf29abcc5826
When to Use This Skill
Use this skill when:
- Composing events over time — UI input, sensor/feed updates, websocket messages, domain events
- You need operators like debounce, throttle, merge, combine-latest, distinct-until-changed
- Building MVVM state with
ReactiveProperty/BindableReactiveProperty - Bridging push-based streams with
Task/asyncandIAsyncEnumerable - Migrating from
System.Reactive, UniRx, orIObservable<T>code - You hit Rx pain points: subscriptions dying on exceptions, scheduler overhead, or leak hunting
Not the right tool for: request/response I/O (use async/await), bounded producer/consumer
with backpressure (use System.Threading.Channels), or server-side stream processing with
batching/backpressure (use Akka.NET Streams). R3, like all Rx, is push-based with no
backpressure. See the csharp-concurrency-patterns skill for choosing between these.
Reference Files
- rx-net-differences.md: Every meaningful difference vs System.Reactive (Rx.NET) — the new core types, the error model, operator renames, dropped APIs, the scheduler swap, and a migration checklist.
- async-and-integration-patterns.md: Common patterns — async dispatch with
AwaitOperation,Taskintegration,IAsyncEnumerableround-tripping,ReactiveProperty/MVVM, subjects, and subscription lifecycle. - scheduling-and-concurrency.md: How R3 handles concurrent updates (the threading contract,
Synchronize,ObserveOn),TimeProvidervsFrameProvider, when each is necessary, and deterministic testing with fake providers.
Everything in this skill was validated empirically against R3 1.3.1. Captured output appears in the reference files as evidence.
Why R3 Exists (the "why use it")
The author (neuecc)
built R3 to fix concrete defects in System.Reactive:
- Exceptions silently kill subscriptions. In Rx, one exception in the pipeline calls
OnErrorand unsubscribes forever — "a billion-dollar mistake" for long-lived event streams (a single bad UI event tears down the whole subscription). R3 routes errors toOnErrorResumeand keeps the subscription alive by default. IScheduleris heavy and confusing.ImmediateScheduler/Mergewere measured causing real server memory/CPU bloat. R3 deletesISchedulerand uses .NET 8'sTimeProvider(wall-clock) plus a newFrameProvider(frame-clock).- Subscription leaks are hard to find. R3 makes every
Observable<T>an abstract class so all subscriptions funnel through one place, enablingObservableTrackerto list every live subscription with stack traces. - Rx and async were awkwardly fused. R3 treats Rx as event-first and adds explicit
bridges (
AwaitOperation,FromAsync,ToAsyncEnumerable) instead of pretending events are pull-based sequences. - One library, every UI. A platform-neutral core plus thin provider packages for Unity, Godot, WPF, WinForms, Avalonia, WinUI3, MAUI, Stride, MonoGame, and Blazor.
Install
dotnet add package R3
# Platform glue (pick what applies): R3.WPF, R3.Avalonia, R3.WinForms, R3.Unity (UPM),
# R3.Godot, ObservableCollections.R3, etc. See the repo README for the full list.
using R3;
The Mental Model
R3 replaces Rx's interfaces with abstract classes, and replaces Rx's two-method error contract with a single completion that carries a result.
public abstract class Observable<T>
{
public IDisposable Subscribe(Observer<T> observer); // tracked centrally
protected abstract IDisposable SubscribeCore(Observer<T> observer);
}
public abstract class Observer<T> : IDisposable // the observer IS the subscription
{
public void OnNext(T value);
public void OnErrorResume(Exception error); // error WITHOUT unsubscribing
public void OnCompleted(Result result); // success OR failure terminates
}
The grammar is (OnNext | OnErrorResume)* OnCompleted(Result)?. Note the difference from Rx's
OnNext* (OnError | OnCompleted)?: errors and termination are decoupled. An error is just a
notification; only OnCompleted ends the stream, and it carries a Result that is either
Result.Success or Result.Failure(exception).
Quick start
using R3;
var subscription = Observable
.EveryValueChanged(model, m => m.SearchText) // emits when the property changes
.Debounce(TimeSpan.FromMilliseconds(300)) // Rx called this "Throttle" (see differences)
.DistinctUntilChanged()
.SubscribeAwait(async (text, ct) =>
{
var results = await _api.SearchAsync(text, ct);
Render(results);
}, AwaitOperation.Switch); // cancel the in-flight search on a new keystroke
// Dispose to unsubscribe; or route into a DisposableBag / AddTo(token).
subscription.Dispose();
Core Behavior, Verified
Errors do not terminate by default
var subject = new Subject<int>();
subject.Select(x => 100 / x).Subscribe(
onNext: x => Console.WriteLine($"next {x}"),
onErrorResume: e => Console.WriteLine($"errorResume {e.GetType().Name}"),
onCompleted: (Result r) => Console.WriteLine($"completed IsSuccess={r.IsSuccess}"));
subject.OnNext(2); // next 50
subject.OnNext(0); // errorResume DivideByZeroException <-- NOT terminated
subject.OnNext(5); // next 20 <-- subscription is still alive!
subject.OnCompleted(); // completed IsSuccess=True
This is the single biggest behavioral change from Rx. To opt back into classic "an error
terminates the sequence" behavior, insert .OnErrorResumeAsFailure() — the error then flows to
OnCompleted(Result.Failure(e)) and downstream OnNexts stop. Recover with Catch. Full
captured runs and the (deliberately absent) Retry story are in
rx-net-differences.md.
Async dispatch is explicit
R3's async operators (SubscribeAwait, SelectAwait, WhereAwait, …) take an AwaitOperation
that decides what happens when values arrive faster than the async work completes:
AwaitOperation | Overlap behavior | Typical use |
|---|---|---|
Sequential (default) | Queue values, run one at a time | Ordered processing |
Drop | Ignore new values while one is running | Debounced submit / cooldown |
Switch | Cancel the running one, start the new | Search-as-you-type, latest-wins |
Parallel | Run all concurrently | Independent fan-out |
SequentialParallel | Run concurrently, emit results in order | Parallel map, ordered output |
ThrottleFirstLast | Run first + last of a burst | Leading/trailing sampling |
These were verified to behave exactly as described (including Switch cancelling the superseded
operation's CancellationToken). See async-and-integration-patterns.md.
Task and IAsyncEnumerable bridges
// Task -> Observable
await Observable.FromAsync(async ct => await LoadAsync(ct)).FirstAsync();
// Observable -> Task (terminal operators return Task<T>)
List<int> all = await source.ToListAsync();
int last = await source.LastAsync();
// IAsyncEnumerable -> Observable, and back
await asyncEnumerable.ToObservable().ForEachAsync(Handle);
await foreach (var x in source.ToAsyncEnumerable()) { /* ... */ }
All verified working. Details and the full terminal-operator list are in async-and-integration-patterns.md.
How R3 Handles Concurrent Updates
R3 does not serialize concurrent producers. Like Rx, it assumes the Rx grammar: OnNext
must not be called concurrently or re-entrantly from multiple threads. Operators (Where,
Select, Subject, …) are not internally locked. Pushing OnNext from many threads at once
into a stateful downstream corrupts state — in testing, 20,000 concurrent OnNext calls into
a List<T> subscriber lost ~half the items and threw inside the operator chain.
The fix is to make the boundary explicit:
// Multiple producer threads -> one serialized consumer
subject.Synchronize() // lock-based gate; delivery becomes single-threaded
.Where(x => x.IsValid)
.Subscribe(Handle); // verified: 10000/10000 items, no corruption
// Or marshal onto a context/threadpool, which also serializes delivery:
source.ObserveOnThreadPool().Subscribe(Handle);
// For shared MVVM state written from many threads:
var counter = new SynchronizedReactiveProperty<int>(0); // thread-safe writes
Practical rule: if more than one thread can publish into a stream, put Synchronize() (or an
ObserveOn*) immediately after the source, or use SynchronizedReactiveProperty. Full race
reproductions and outputs are in scheduling-and-concurrency.md.
Time vs Frames: TimeProvider and FrameProvider
R3 has two notions of "when," and both are abstractions you can fake in tests:
TimeProvider(the .NET 8 BCL type) = wall-clock time. Used byDelay,Debounce,Interval,Timer,Timeout. This is what server/business code uses.FrameProvider(R3-specific) = a frame clock. Used byEveryUpdate,DelayFrame(n),IntervalFrame(n), etc.
When is a FrameProvider necessary? Whenever "progress" is measured in render/update ticks instead of elapsed time:
- Game engines (Unity, Godot, Stride, MonoGame) — logic ticks with the engine's update loop, so it respects pause and time-scale and stays in lockstep with rendering.
- UI render loops (WPF/Avalonia/WinUI composition frames) — react per frame.
- Deterministic tests —
FakeFrameProvider.Advance(n)drives frames with zero real time, exactly asFakeTimeProvider.Advance(timeSpan)drives the clock.
Plain server/business code virtually never needs FrameProvider — that's TimeProvider
territory. Both fakes make time-dependent pipelines fully deterministic; examples in
scheduling-and-concurrency.md.
Best Practices Summary
DO
- Treat
OnErrorResumeas the default: design streams that survive individual bad events. - Add
.OnErrorResumeAsFailure()when you genuinely want an error to terminate the stream. - Choose an
AwaitOperationdeliberately for every async operator (Switchfor latest-wins,Sequentialfor ordering,Dropfor cooldowns). - Put
Synchronize()/ObserveOn*after any source that multiple threads publish into. - Pass a
TimeProviderto time operators and aFrameProviderto frame operators so tests can useFakeTimeProvider/FakeFrameProvider. - Manage lifetime: route subscriptions into a
DisposableBag,CompositeDisposable, or.AddTo(cancellationToken); turn onObservableTrackerin dev to catch leaks. - Use
ReactivePropertyfor de-duplicated observable state;BindableReactivePropertyfor XAML-bound state.
DON'T
- Don't assume an exception ends the stream (that's Rx, not R3).
- Don't reach for Rx names that R3 renamed: it's
Debounce(notThrottle),ThrottleLast(notSample),Chunk(notBuffer).Retry,GroupBy,Finally, and plainBufferare absent in 1.3.1 — see the differences file for replacements. - Don't call
OnNextconcurrently/re-entrantly from multiple threads withoutSynchronize(). - Don't use R3 for backpressured throughput pipelines — use Channels or Akka.NET Streams.
- Don't block on terminal operators (
.Result/.Wait()); they returnTask<T>—awaitthem.
Additional Resources
- R3 repository: https://github.com/Cysharp/R3
- Full README / operator reference: https://github.com/Cysharp/R3/blob/main/README.md
- Design rationale (neuecc): https://neuecc.medium.com/r3-a-new-modern-reimplementation-of-reactive-extensions-for-c-cf29abcc5826
- NuGet: https://www.nuget.org/packages/R3
TimeProvider(BCL): https://learn.microsoft.com/en-us/dotnet/api/system.timeproviderFakeTimeProvider: https://www.nuget.org/packages/Microsoft.Extensions.TimeProvider.Testing- Related skill:
csharp-concurrency-patterns(choosing R3 vs async/await vs Channels vs Akka.NET)
Frequently asked questions about R3 Reactive Extensions
Similar skills
Python PyPI Package Builder
Streamline the process of creating and publishing Python packages.
Minecraft Plugin Development
Streamline your Minecraft server plugin creation.
MCP Server Builder
Easily build .NET MCP servers with the latest standards.
CommunityToolkit.Mvvm Messenger
Decoupled communication for ViewModels in .NET applications.
MVVM Toolkit DI
Streamline ViewModel integration with Dependency Injection in .NET.
MCP Apps Builder
Essential guidelines for MCP server development.
