К основному содержанию
скилл CX Codex

r3-reactive-extensions — скилл для Claude Code: R3 в C#

Скилл r3-reactive-extensions помогает собирать реактивные потоки на R3 и разбираться с ошибками, асинхронным кодом и планированием событий. Пригодится при работе с UI-событиями и миграции с Rx.NET.

MIT 170 установок ★ 1 271 обновлён 2026-10-11

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add Aaronontheweb/dotnet-skills --skill r3-reactive-extensions -a claude-code
Открыть на GitHub

Что делает r3-reactive-extensions

Скилл объясняет модель Observable<T> и Observer<T> в R3: ошибки через OnErrorResume сами по себе не завершают поток, а завершение передаёт Result. В руководстве также разобраны операторы для потоков событий и работа с ReactiveProperty в MVVM.

Отдельные материалы посвящены связке с Task и IAsyncEnumerable, асинхронной обработке через AwaitOperation, планированию с TimeProvider и FrameProvider, а также потокобезопасности и проверкам с фиктивными провайдерами. Есть разбор отличий от System.Reactive и памятка по миграции.

R3 работает по push-модели без backpressure. Для запросов и ответов руководство советует async/await, а для потоков с backpressure — System.Threading.Channels; это важно учесть при выборе схемы обработки.

Какие задачи решает

  • обрабатывать последовательность UI-событий с debounce
  • сохранять подписку после ошибки в потоке
  • связать Observable с Task или IAsyncEnumerable
  • выбрать TimeProvider или FrameProvider для расписания
  • перенести код с Rx.NET на R3

Примеры запросов агенту

  • Покажи, как обработать изменения SearchText через R3 с debounce и отменой предыдущего поиска.
  • Объясни, почему ошибка в R3 не завершает подписку и как устроен OnCompleted с Result.
  • Помоги перенести этот код с System.Reactive на R3 и укажи отличия в планировании.

Как установить r3-reactive-extensions

1Через Skills CLI (Vercel)

npx skills add Aaronontheweb/dotnet-skills --skill r3-reactive-extensions -a claude-code

2Вручную: положить файлы

~/.claude/skills/r3-reactive-extensions/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/r3-reactive-extensions/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о r3-reactive-extensions

Как установить r3-reactive-extensions в Claude Code?

Выполните npx skills add Aaronontheweb/dotnet-skills --skill r3-reactive-extensions -a claude-code. Файл скилла появится по пути ~/.claude/skills/r3-reactive-extensions/SKILL.md.

Что делает r3-reactive-extensions?

Скилл разбирает реактивное программирование на R3 в C#: модель потоков, обработку ошибок, асинхронные мосты и планирование. Он также объясняет отличия R3 от Rx.NET.

Чем обработка ошибок в R3 отличается от Rx.NET?

В R3 OnErrorResume сообщает об ошибке, но не завершает поток. Завершение передаётся отдельно через OnCompleted с Result.

Исходный текст

SKILL.md · MIT
---
name: r3-reactive-extensions
description: Build reactive/event-driven C# with R3 (Cysharp's modern reimplementation of Reactive Extensions). Covers the Observable<T>/Observer<T> model, the OnErrorResume error contract, async dispatch with AwaitOperation, Task/IAsyncEnumerable integration, TimeProvider/FrameProvider scheduling, the concurrency contract, and how R3 differs from System.Reactive (Rx.NET).
user-invocable: false
---

# R3: Modern Reactive Extensions for .NET

R3 is [Cysharp's](https://github.com/Cysharp/R3) 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` / `async` and `IAsyncEnumerable`
- Migrating from `System.Reactive`, UniRx, or `IObservable<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](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](async-and-integration-patterns.md): Common patterns — async dispatch with `AwaitOperation`, `Task` integration, `IAsyncEnumerable` round-tripping, `ReactiveProperty`/MVVM, subjects, and subscription lifecycle.
- [scheduling-and-concurrency.md](scheduling-and-concurrency.md): How R3 handles **concurrent updates** (the threading contract, `Synchronize`, `ObserveOn`), `TimeProvider` vs `FrameProvider`, 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](https://neuecc.medium.com/r3-a-new-modern-reimplementation-of-reactive-extensions-for-c-cf29abcc5826))
built R3 to fix concrete defects in `System.Reactive`:

1. **Exceptions silently kill subscriptions.** In Rx, one exception in the pipeline calls
   `OnError` and *unsubscribes forever* — "a billion-dollar mistake" for long-lived event
   streams (a single bad UI event tears down the whole subscription). R3 routes errors to
   `OnErrorResume` and **keeps the subscription alive by default**.
2. **`IScheduler` is heavy and confusing.** `ImmediateScheduler`/`Merge` were measured causing
   real server memory/CPU bloat. R3 deletes `IScheduler` and uses .NET 8's `TimeProvider`
   (wall-clock) plus a new `FrameProvider` (frame-clock).
3. **Subscription leaks are hard to find.** R3 makes every `Observable<T>` an abstract class so
   all subscriptions funnel through one place, enabling `ObservableTracker` to list every live
   subscription with stack traces.
4. **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.
5. **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

```bash
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.
```

```csharp
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.

```csharp
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

```csharp
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

```csharp
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 `OnNext`s stop. Recover with `Catch`. Full
captured runs and the (deliberately absent) `Retry` story are in
[rx-net-differences.md](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](async-and-integration-patterns.md).

### Task and IAsyncEnumerable bridges

```csharp
// 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](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:

```csharp
// 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](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 by `Delay`, `Debounce`,
  `Interval`, `Timer`, `Timeout`. This is what server/business code uses.
- **`FrameProvider`** (R3-specific) = a *frame clock*. Used by `EveryUpdate`, `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 as `FakeTimeProvider.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](scheduling-and-concurrency.md).

---

## Best Practices Summary

### DO
- Treat `OnErrorResume` as the default: design streams that survive individual bad events.
- Add `.OnErrorResumeAsFailure()` when you genuinely want an error to terminate the stream.
- Choose an `AwaitOperation` deliberately for every async operator (`Switch` for latest-wins,
  `Sequential` for ordering, `Drop` for cooldowns).
- Put `Synchronize()` / `ObserveOn*` after any source that multiple threads publish into.
- Pass a `TimeProvider` to time operators and a `FrameProvider` to frame operators so tests can
  use `FakeTimeProvider` / `FakeFrameProvider`.
- Manage lifetime: route subscriptions into a `DisposableBag`, `CompositeDisposable`, or
  `.AddTo(cancellationToken)`; turn on `ObservableTracker` in dev to catch leaks.
- Use `ReactiveProperty` for de-duplicated observable state; `BindableReactiveProperty` for
  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` (not `Throttle`), `ThrottleLast`
  (not `Sample`), `Chunk` (not `Buffer`). `Retry`, `GroupBy`, `Finally`, and plain `Buffer` are
  **absent** in 1.3.1 — see the differences file for replacements.
- Don't call `OnNext` concurrently/re-entrantly from multiple threads without `Synchronize()`.
- Don't use R3 for backpressured throughput pipelines — use Channels or Akka.NET Streams.
- Don't block on terminal operators (`.Result`/`.Wait()`); they return `Task<T>` — `await` them.

---

## 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.timeprovider
- **`FakeTimeProvider`:** https://www.nuget.org/packages/Microsoft.Extensions.TimeProvider.Testing
- **Related skill:** `csharp-concurrency-patterns` (choosing R3 vs async/await vs Channels vs Akka.NET)

© Aaronontheweb · MIT · Aaronontheweb/dotnet-skills

Похожие скиллы

Все скиллы по теме «Языки программирования» →
reactive-programming aj-geddes Скилл reactive-programming для Claude Code помогает строить реактивные потоки для интерфейсов, событий и асинхронных данных. Подключается к задачам с RxJS, потоками событий и управлением состоянием. CX Codex +1 498установок microsoft-extensions-ai managedcode Скилл для работы с Microsoft.Extensions.AI в .NET: чат-клиенты, эмбеддинги, инструменты, структурированный вывод и оценка без привязки к одному провайдеру. CX Codex +1 ★ 521звёзд репо reactive-comment elvisun Скилл reactive-comment проверяет запросы журналистов на соответствие вашей экспертизе и готовит ответ только для подходящих случаев. Нужен перед питчем в HARO, Qwoted и похожих сервисах. CX Codex +1 757установок reactive-dashboard-performance curiositech Скилл reactive-dashboard-performance настраивает быстрый рендеринг дашбордов на React и ускоряет асинхронные тесты. Помогает внедрить скелетоны, настроить React Query и убрать таймауты в тестах. CX Codex +1 220установок audio-reactive-video-composition calesthio Скилл audio-reactive-video-composition для Claude Code связывает аудиометки с детерминированным таймингом видео. Направляет монтажные склейки, генеративные анимации и титры по ритму и спектру трека. CX Codex +1 170установок audio-reactive Bbeierle12 Скилл audio-reactive связывает частотный анализ звука с анимацией интерфейса, частицами и 3D-сценами. CX Codex +1 108установок

Из того же набора35

Весь набор →
verify-email-snapshots Скилл verify-email-snapshots для снапшот-тестирования HTML-писем через Verify: рендер шаблона сравнивается с утверждённым эталоном, и тест падает при расхождении. CX Codex +1 445установок akka-hosting-actor-patterns Скилл akka-hosting-actor-patterns для Claude Code задаёт паттерны сущностных акторов Akka.NET через Akka.Hosting для локальных тестов и кластерного продакшена. CX Codex +1 443установок opentelemetry-net-instrumentation Скилл opentelemetry-net-instrumentation для Claude Code расставляет трассировку, метрики и логи в .NET-коде по спецификации OpenTelemetry. Покрывает телеметрией библиотеку или приложение. CX Codex +1 442установок akka-net-testing-patterns Скилл akka-net-testing-patterns для написания юнит- и интеграционных тестов акторов Akka.NET на Akka.Hosting.TestKit: внедрение зависимостей, TestProbes, проверка персистентности. CX Codex +1 440установок akka-net-management Скилл akka-net-management подсказывает агенту, как настроить Akka.Management и Cluster Bootstrap: динамическое обнаружение узлов, health-эндпоинты, работа в Kubernetes и Azure. CX Codex +1 439установок akka-net-aspire-configuration Скилл akka-net-aspire-configuration помогает связать Akka.NET и .NET Aspire: актор-система, кластер, персистентность и Akka.Management в одном проекте. CX Codex +1 425установок marketplace-publishing Скилл marketplace-publishing для Claude Code описывает путь от новой папки со SKILL.md до тега релиза в маркетплейсе dotnet-skills. Ведёт собственный каталог плагинов. CX Codex +1 419установок csharp-nullable-reference-types Скилл csharp-nullable-reference-types помогает внедрять nullable reference types в C#, настраивать flow-анализ и расставлять атрибуты из System.Diagnostics.CodeAnalysis без лишних правок. CX Codex +1 165установок

Спонсоры проекта

Компании, которые помогают держать аналитику открытой