Configs2026年7月21日·1 分钟阅读

Rx.NET — Reactive Extensions for .NET

Rx.NET (System.Reactive) brings the observer pattern and LINQ-style query operators to asynchronous and event-based data streams in .NET, enabling composable and declarative async programming.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Rx.NET
直接安装命令
npx -y tokrepo@latest install 40fde89a-8500-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Rx.NET is the .NET implementation of Reactive Extensions, a library for composing asynchronous and event-based programs using observable sequences. It provides a rich set of LINQ operators to filter, project, aggregate, and combine streams of data, making complex async workflows easier to reason about and maintain.

What Rx.NET Does

  • Models push-based data streams with IObservable<T> and IObserver<T>
  • Provides 100+ LINQ-style operators for stream composition (Select, Where, Merge, Zip, Buffer, etc.)
  • Manages concurrency and scheduling through pluggable schedulers
  • Bridges events, tasks, and async enumerables into observable sequences
  • Supports backpressure handling and error recovery operators

Architecture Overview

Rx.NET is built around the IObservable<T> / IObserver<T> duality to IEnumerable<T> / IEnumerator<T>. Operators are implemented as extension methods that compose observable pipelines lazily. Schedulers abstract threading and timing, allowing the same pipeline to run on thread pools, UI dispatchers, or test schedulers. The library ships as several NuGet packages: System.Reactive (core), System.Reactive.Linq (operators), and platform-specific bindings.

Self-Hosting & Configuration

  • Install via NuGet: dotnet add package System.Reactive
  • Targets .NET Standard 2.0, compatible with .NET Framework 4.7+, .NET 6-9
  • No external services or configuration files needed
  • Choose schedulers for concurrency: TaskPoolScheduler, CurrentThreadScheduler, DispatcherScheduler
  • Add System.Reactive.Testing for unit-testing time-dependent streams with TestScheduler

Key Features

  • Declarative composition of async event streams with LINQ syntax
  • Hot and cold observable support for flexible subscription models
  • Built-in error handling operators: Retry, Catch, OnErrorResumeNext
  • Time-based operators: Throttle, Debounce, Sample, Delay, Timeout
  • Subjects for multicasting and bridging imperative and reactive code

Comparison with Similar Tools

  • async/await + IAsyncEnumerable — pull-based; Rx.NET is push-based with richer temporal operators
  • System.Threading.Channels — bounded producer-consumer; no built-in composition operators
  • MediatR — in-process request/response mediator; Rx.NET handles continuous data streams
  • TPL Dataflow — block-based pipeline; Rx.NET has more composable operator vocabulary
  • Akka.NET Streams — actor-based streaming; heavier runtime, built-in backpressure

FAQ

Q: When should I use Rx.NET instead of async/await? A: Use Rx.NET when you need to compose multiple event sources, apply time-based operators, or process continuous streams. For single async operations, async/await is simpler.

Q: Does Rx.NET work with Blazor and MAUI? A: Yes. The core System.Reactive package targets .NET Standard 2.0 and runs on all modern .NET platforms.

Q: How do I test time-dependent Rx.NET code? A: Use TestScheduler from System.Reactive.Testing to advance virtual time and assert on emitted values deterministically.

Q: Is Rx.NET still maintained? A: Yes. The project moved under the dotnet organization on GitHub and continues to receive updates and community contributions.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产