Update README and related docs (#1933)
This commit is contained in:
Родитель
2852824dc4
Коммит
df7da6a220
|
@ -194,3 +194,10 @@ nuget.exe
|
|||
*.v3.ncrunchproject
|
||||
*.v3.ncrunchsolution
|
||||
/Rx.NET/Source/.NCrunch_*/StoredText
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
|
|
|
@ -14,7 +14,11 @@ Arthur Watson
|
|||
Gert Drapers
|
||||
Mark Shields
|
||||
Eric Rozell
|
||||
Oren Novotny
|
||||
Claire Novotny
|
||||
Geoffrey Huntley
|
||||
David Karnok
|
||||
Daniel C. Weber
|
||||
|
||||
|
||||
Rx.js and Ix.js:
|
||||
Matthew Podwysocki
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
# The pre-2023 README
|
||||
|
||||
By early 2023, the main README had become a bit of a dumping ground for information, most of which was at an inappropriate level of detail for someone visiting the repo for the first time to find out what it was about.
|
||||
|
||||
However, most of the information in there would be of some use to someone, so we've moved the more obscure bits out into this file so that they don't vanish entirely.
|
||||
|
||||
## A Brief Intro
|
||||
|
||||
(**Note:** none of this was untrue, but it focused on detail without really saying what Rx is actually for.)
|
||||
|
||||
The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. Using Rx, developers *__represent__* asynchronous data streams with [Observables](https://docs.microsoft.com/dotnet/api/system.iobservable-1), *__query__* asynchronous data streams using [LINQ operators](http://msdn.microsoft.com/en-us/library/hh242983.aspx), and *__parameterize__* the concurrency in the asynchronous data streams using [Schedulers](http://msdn.microsoft.com/en-us/library/hh242963.aspx). Simply put, Rx = Observables + LINQ + Schedulers.
|
||||
|
||||
Whether you are authoring a traditional desktop or web-based application, you have to deal with asynchronous and event-based programming from time to time. Desktop applications have I/O operations and computationally expensive tasks that might take a long time to complete and potentially block other active threads. Furthermore, handling exceptions, cancellation, and synchronization is difficult and error-prone.
|
||||
|
||||
Using Rx, you can represent multiple asynchronous data streams (that come from diverse sources, e.g., stock quote, tweets, computer events, web service requests, etc.), and subscribe to the event stream using the `IObserver<T>` interface. The `IObservable<T>` interface notifies the subscribed `IObserver<T>` interface whenever an event occurs.
|
||||
|
||||
Because observable sequences are data streams, you can query them using standard LINQ query operators implemented by the Observable extension methods. Thus you can filter, project, aggregate, compose and perform time-based operations on multiple events easily by using these standard LINQ operators. In addition, there are a number of other reactive stream specific operators that allow powerful queries to be written. Cancellation, exceptions, and synchronization are also handled gracefully by using the extension methods provided by Rx.
|
||||
|
||||
Rx complements and interoperates smoothly with both synchronous data streams (`IEnumerable<T>`) and single-value asynchronous computations (`Task<T>`) as the following diagram shows:
|
||||
|
||||
|
||||
<table>
|
||||
<th></th><th>Single return value</th><th>Multiple return values</th>
|
||||
<tr>
|
||||
<td>Pull/Synchronous/Interactive</td>
|
||||
<td>T</td>
|
||||
<td>IEnumerable<T></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Push/Asynchronous/Reactive</td>
|
||||
<td>Task<T></td>
|
||||
<td>IObservable<T></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Additional documentation, video, tutorials and HOL are available on [MSDN](https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh242985(v=vs.103)), on [*Introduction to Rx*](http://introtorx.com/), [*ReactiveX*](http://reactivex.io/), and [ReactiveUI](https://reactiveui.net/).
|
||||
|
||||
|
||||
## Flavors of Rx
|
||||
|
||||
* __Rx.NET__: *(this repository)* The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators.
|
||||
* [RxJS](https://github.com/ReactiveX/rxjs): The Reactive Extensions for JavaScript (RxJS) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in JavaScript which can target both the browser and Node.js.
|
||||
* [RxJava](https://github.com/ReactiveX/RxJava): Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
|
||||
* [RxScala](https://github.com/ReactiveX/RxScala): Reactive Extensions for Scala – a library for composing asynchronous and event-based programs using observable sequences
|
||||
* [RxCpp](https://github.com/Reactive-Extensions/RxCpp): The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C and C++.
|
||||
* [RxPy](https://github.com/ReactiveX/RxPY): The Reactive Extensions for Python 3 (Rx.Py) is a set of libraries to compose asynchronous and event-based programs using observable collections and LINQ-style query operators in Python 3.
|
||||
|
||||
|
||||
## Applications
|
||||
|
||||
* [Tx](https://github.com/Reactive-Extensions/Tx): a set of code samples showing how to use LINQ to events, such as real-time standing queries and queries on past history from trace and log files, which targets ETW, Windows Event Logs and SQL Server Extended Events.
|
||||
* [LINQ2Charts](http://linq2charts.codeplex.com): an example for Rx bindings. Similar to existing APIs like LINQ to XML, it allows developers to use LINQ to create/change/update charts in an easy way and avoid having to deal with XML or other underneath data structures. We would love to see more Rx bindings like this one.
|
|
@ -0,0 +1,21 @@
|
|||
# Ix Release History v5.0 and Older
|
||||
|
||||
In addition to the original `System.Interactive` library, and the `System.Interactive.Async` library that added the same functionality for `IAsyncEnumerable<T>`, the Ix.NET project also includes `System.Linq.Async`, which defines for `IAsyncEnumerable<T>` the same LINQ operators that are built into the .NET runtime libraries for `IEnumerable<T>`.
|
||||
|
||||
## V5.1
|
||||
|
||||
Removed various `IEnumerable<T>` min and max extension methods because .NET 6.0 now has built-in equivalents.
|
||||
|
||||
Fixed bug causing duplicate emissions from `Delay`.
|
||||
|
||||
|
||||
## V5.0
|
||||
|
||||
`System.Linq.Async` adds support for C# 8.0's nullable reference types feature.
|
||||
|
||||
|
||||
## v4.0
|
||||
|
||||
Ix Async 4.0 has a breaking change from prior versions due to `IAsyncEnumerable<T>` being added to the .NET runtime libraries. In earlier versions, Ix Async defined its own version of this interface, but v4.0 has been modified to use the definition now built into the runtime. This enables the `IAsyncEnumerable` implementations in Ix Async to be consumed by the [async streams](https://github.com/dotnet/roslyn/blob/master/docs/features/async-streams.md) language feature that was added in C# 8. This means for .NET Standard 2.1 and .NET Core 3 targets, we use the in-box interfaces for `IAsyncEnumerable<T>` and friends. On other platforms, we use the `IAsyncEnumerable` definition from `Microsoft.Bcl.AsyncInterfaces`, supplying a full implementation of the Rx-like LINQ operators Ix has long defined for `IEnumerable<T>`. The types will unify to the system ones where the platform provides it.
|
||||
|
||||
The .NET runtime libraries did not add a full LINQ to Objects implementation for `IAsyncEnumerable<T>`. Whereas `IEnumerable<T>` offers standard operators such as `Where`, `Single`, and `GroupBy`, enabling use of the LINQ query expression syntax, this is not available out of the box with .NET for `IAsyncEnumerable<T>`. Since earlier versions of this library had already done most of the relevant work to implement these operators on its pre-v4.0 version of `IAsyncEnumerable<T>`, v4.0 of Ix also builds the `System.Linq.Async` library, making LINQ to Objects available for `IAsyncEnumerable<T>`.
|
|
@ -0,0 +1,9 @@
|
|||
# Ix Release History v6.0
|
||||
|
||||
|
||||
## v6.0.1
|
||||
|
||||
First release with version number updated to v6.0.x. (At the time, Rx and Ix were attempting to follow a policy of keeping version numbers aligned with the .NET runtime libraries.)
|
||||
|
||||
Added `MinByWithTies` and `MaxByWithTies` to reinstate functionality that was lost in v5.1. (When .NET 6.0 added its own MinBy/MaxBy, Ix v5.1 removed its methods, but some of those did things the .NET 6.0 versions can't.)
|
||||
|
207
README.md
207
README.md
|
@ -1,136 +1,105 @@
|
|||
Reactive Extensions
|
||||
======================
|
||||
|
||||
Channel | Rx | Ix |
|
||||
-------- | :------------: | :-------------: |
|
||||
Build | [![Build Status](https://dev.azure.com/dotnet/Rx.NET/_apis/build/status/Rx.NET-CI?branchName=master)](https://dev.azure.com/dotnet/Rx.NET/_build/latest?definitionId=9) | [![Build Status](https://dev.azure.com/dotnet/Rx.NET/_apis/build/status/Ix.NET-CI?branchName=master)](https://dev.azure.com/dotnet/Rx.NET/_build/latest?definitionId=28)
|
||||
NuGet.org | [![#](https://img.shields.io/nuget/v/System.Reactive.svg)](https://www.nuget.org/packages/System.Reactive/) | [![#](https://img.shields.io/nuget/v/System.Interactive.svg)](https://www.nuget.org/packages/System.Interactive/)
|
||||
[Azure<br>Artifacts](https://dev.azure.com/dotnet/Rx.NET/_packaging?_a=feed&feed=RxNet) | [![System.Reactive package in RxNet feed in Azure Artifacts](https://azpkgsshield.azurevoodoo.net/dotnet/Rx.NET/RxNet/System.Reactive)](https://dev.azure.com/dotnet/Rx.NET/_packaging?_a=package&feed=5afc77bd-23b4-46f8-b725-40ebedab630c&package=3c02dce4-f7e9-43ec-a014-28ea9fc46f82&preferRelease=true) | [![System.Interactive package in RxNet feed in Azure Artifacts](https://azpkgsshield.azurevoodoo.net/dotnet/Rx.NET/RxNet/System.Interactive)](https://dev.azure.com/dotnet/Rx.NET/_packaging?_a=package&feed=5afc77bd-23b4-46f8-b725-40ebedab630c&package=a3311bc0-c6ea-4460-bea8-b65d633e2583&preferRelease=true)
|
||||
This repository contains four libraries which are conceptually related in that they are all concerned with LINQ over sequences of things:
|
||||
|
||||
* [Reactive Extensions for .NET](Rx.NET/) aka Rx.NET or Rx ([System.Reactive](https://www.nuget.org/packages/System.Reactive/)): a library for event-driven programming with a composable, declarative model
|
||||
* [AsyncRx.NET](AsyncRx.NET/) (experimental preview) ([System.Reactive.Async](https://www.nuget.org/packages/System.Reactive.Async)): experimental implementation of Rx for `IAsyncObservable<T>` offering deeper `async`/`await` support
|
||||
* [Interactive Extensions for .NET](Ix.NET/), aka Ix ([System.Interactive](https://www.nuget.org/packages/System.Interactive/)): extended LINQ operators for `IAsyncEnumerable` and `IEnumerable`
|
||||
* [LINQ for `IAsyncEnumerable`](./Ix.NET/Source/System.Linq.Async/) ([System.Linq.Async](https://www.nuget.org/packages/System.Linq.Async/)): implements standard LINQ operators for `IAsyncEnumerable`
|
||||
|
||||
Each will be described later in this README.
|
||||
|
||||
## Getting the bits
|
||||
|
||||
Channel | Rx | AsyncRx | Ix | System.Linq.Async
|
||||
--- | --- | --- | --- |--- |
|
||||
NuGet.org | [![#](https://img.shields.io/nuget/v/System.Reactive.svg)](https://www.nuget.org/packages/System.Reactive/)| [![#](https://img.shields.io/nuget/v/System.Reactive.Async.svg)](https://www.nuget.org/packages/System.Reactive.Async/) | [![#](https://img.shields.io/nuget/v/System.Interactive.svg)](https://www.nuget.org/packages/System.Interactive/) | [![#](https://img.shields.io/nuget/v/System.Linq.Async.svg)](https://www.nuget.org/packages/System.Linq.Async/)
|
||||
NuGet.org preview (if newer than release) | [![#](https://img.shields.io/nuget/vpre/System.Reactive.svg)](https://www.nuget.org/packages/System.Reactive/) | [![#](https://img.shields.io/nuget/vpre/System.Reactive.Async.svg)](https://www.nuget.org/packages/System.Reactive.Async/) | [![#](https://img.shields.io/nuget/vpre/System.Interactive.svg)](https://www.nuget.org/packages/System.Interactive/) | [![#](https://img.shields.io/nuget/vpre/System.Linq.Async.svg)](https://www.nuget.org/packages/System.Linq.Async/)
|
||||
Build | [![Build Status](https://dev.azure.com/dotnet/Rx.NET/_apis/build/status/Rx.NET-CI?branchName=main)](https://dev.azure.com/dotnet/Rx.NET/_build/latest?definitionId=9) | [![Build Status](https://dev.azure.com/dotnet/Rx.NET/_apis/build/status/AsyncRx.NET-CI?branchName=main)](https://dev.azure.com/dotnet/Rx.NET/_build/latest?definitionId=191) | [![Build Status](https://dev.azure.com/dotnet/Rx.NET/_apis/build/status/Ix.NET-CI?branchName=main)](https://dev.azure.com/dotnet/Rx.NET/_build/latest?definitionId=28) | Built as part of Ix
|
||||
[Azure<br>Artifacts](https://dev.azure.com/dotnet/Rx.NET/_packaging?_a=feed&feed=RxNet) | [![System.Reactive package in RxNet feed in Azure Artifacts](https://azpkgsshield.azurevoodoo.net/dotnet/Rx.NET/RxNet/System.Reactive)](https://dev.azure.com/dotnet/Rx.NET/_packaging?_a=package&feed=5afc77bd-23b4-46f8-b725-40ebedab630c&package=3c02dce4-f7e9-43ec-a014-28ea9fc46f82&preferRelease=true) | [![System.Reactive.Async package in RxNet feed in Azure Artifacts](https://azpkgsshield.azurevoodoo.net/dotnet/Rx.NET/RxNet/System.Reactive.Async)](https://dev.azure.com/dotnet/Rx.NET/_artifacts/feed/RxNet/NuGet/System.Reactive.Async/&preferRelease=true) | [![System.Interactive package in RxNet feed in Azure Artifacts](https://azpkgsshield.azurevoodoo.net/dotnet/Rx.NET/RxNet/System.Interactive)](https://dev.azure.com/dotnet/Rx.NET/_packaging?_a=package&feed=5afc77bd-23b4-46f8-b725-40ebedab630c&package=a3311bc0-c6ea-4460-bea8-b65d633e2583&preferRelease=true) | [![System.Linq.Async package in RxNet feed in Azure Artifacts](https://azpkgsshield.azurevoodoo.net/dotnet/Rx.NET/RxNet/System.Linq.Async)](https://dev.azure.com/dotnet/Rx.NET/_artifacts/feed/RxNet/NuGet/System.Linq.Async/&preferRelease=true)
|
||||
Release history | [ReleaseHistory](Rx.NET/Documentation/ReleaseHistory/) | [ReleaseHistory](Ix.NET/Documentation/ReleaseHistory/)| [ReleaseHistory](Ix.NET/Documentation/ReleaseHistory/)
|
||||
|
||||
For nightly builds, configure NuGet to use this feed: `https://pkgs.dev.azure.com/dotnet/Rx.NET/_packaging/RxNet/nuget/v3/index.json`
|
||||
|
||||
### Join the conversation
|
||||
|
||||
Catch us in the #rxnet channel over at http://reactiveui.net/slack
|
||||
|
||||
### Get nightly builds
|
||||
- NuGet v3 feed url (VS 2015+): `https://pkgs.dev.azure.com/dotnet/Rx.NET/_packaging/RxNet/nuget/v3/index.json`
|
||||
|
||||
## System.Linq.Async / System.Interactive.Async / System.Interactive
|
||||
## A Brief Introduction to Rx
|
||||
|
||||
### v4.0 changes
|
||||
In this digital age, live data streams are ubiquitous. Financial applications depend on a swift response to timely information. Computer networks have always been able to provide extensive information about their health and operation. Utility companies such as water providers have vast numbers of devices monitoring their operations. User interface and game building frameworks report user interactions in great detail. Delivery vans continuously report their progress. Aircraft provide performance telemetry to detect potential maintenance issues before they become serious problems, and cars are now starting to do the same. Many of us wear or carry devices that track our physical activity and even [vital signs](https://www.youtube.com/watch?v=6yjl_h7-WYA&t=2443s). And the improvements in machine learning have enriched the insights that can be derived from the ever-increasing volume and variety of live data.
|
||||
|
||||
Ix Async 4.0 has a breaking change from prior versions due to being the first LINQ implementation
|
||||
to support the new C# 8 [async streams](https://github.com/dotnet/roslyn/blob/master/docs/features/async-streams.md) feature. This means for .NET Standard 2.1 and .NET Core 3 targets, we use the in-box interfaces for `IAsyncEnumerable<T>` and friends. On other platforms, we provide the implementation, so you can use `await foreach` and create async iterators as you would expect. The types will unify to the system ones where the platform provides it.
|
||||
But despite being so widespread, live information streams have always been something of a second class citizen. Almost all programming languages have some innate way to work with lists of data (e.g., arrays), but these mechanisms tend to presume that the relevant data is already sitting in memory, ready for us to work with it. What's missing is the liveness—the fact that an information source might produce new data at any moment, on its own schedule.
|
||||
|
||||
There are many breaking changes here; a full set of changenotes is on the way.
|
||||
Rx elevates the support for live streams of information to the same level as we expect for things like arrays. Here's an example:
|
||||
|
||||
## System.Reactive
|
||||
```cs
|
||||
var bigTrades =
|
||||
from trade in trades
|
||||
where trade.Volume > 1_000_000;
|
||||
```
|
||||
|
||||
### v5.0 changes
|
||||
Rx.NET v5 is required for .NET 5 support of CSWinRT; earlier versions of Rx won't work correctly. To get the Windows API, you need to use the latest Windows SDK (19041), though you can target earlier versions of Windows.
|
||||
This uses C#'s LINQ feature to filter `trades` down to those entities with a volume greater than one million. This query expression syntax is just a shorthand for method calls, so we could also write it this way:
|
||||
|
||||
**Breaking changes**
|
||||
In Windows, since the `net5.0-windows10.0.19041` target now supports all Windows desktop object models, on UWP `DispatcherObservable` and releated SubscribeOn/ObserveOn were renamed to be `CoreDispatcherObservable`, `SubscribeOnCoreDispatcher`, and `ObserveOnCoreDispatcher`. This reflects the OS type names. `Dispatcher` refers only to the WPF type.
|
||||
```cs
|
||||
var bigTrades = trades.Where(trade => trade.Volume > 1_000_000);
|
||||
```
|
||||
|
||||
#### Supported Platforms
|
||||
Rx 5.x supports the following platforms
|
||||
The exact behaviour of these two (equivalent) code snippets depends on what type `trades` has. If it were a `IEnumerable<Trade>`, then this query would just iterate through the list, and `bigTrades` would be an enumerable sequence containing just the matching objects. If `trades` were an object representing a database table (e.g., an [Entity Framework](https://learn.microsoft.com/en-us/ef/core/) [DbSet](https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbset-1), this would be translated into a database query. But if we're using Rx, `trades` would be an `IObservable<Trade>`, an object reporting live events as they happen. And `bigTrades` would also be an `IObservable<Trade>`, reporting only those trades with a volume over a million. We can provide Rx with a callback to be invoked each time an observable source has something for us:
|
||||
|
||||
- .NET 5
|
||||
- .NET 5 with the Windows 10 19041 SDK (able to target earlier Windows versions)
|
||||
- .NET Framework 4.7
|
||||
- UWP 10.0.16299
|
||||
- .NET Standard 2.0
|
||||
```cs
|
||||
bigTrades.Subscribe(t => Console.WriteLine($"{t.Symbol}: trade with volume {t.Volume}"));
|
||||
```
|
||||
|
||||
Support for UWP 10.0 has been removed.
|
||||
The two key features of Rx are:
|
||||
|
||||
### v4.0 changes
|
||||
Due to the [overwhelming](https://github.com/dotnet/reactive/issues/299) [pain](https://github.com/dotnet/reactive/issues/305) that fixing [#205 - Implement assembly version strategy](https://github.com/dotnet/reactive/issues/205) caused, we have refactored the libraries into a single library `System.Reactive`. To prevent breaking existing code that references the v3 libraries, we have facades with TypeForwarders to the new assembly. If you have a reference to a binary built against v3.0, then use the new `System.Reactive.Compatibility` package.
|
||||
* a clearly defined way to represent and handle live sequences of data ([`IObservable<T>`](https://learn.microsoft.com/en-us/dotnet/api/system.iobservable-1))
|
||||
* a set of operators (such as the `Where` operator just shown) enabling event processing logic to be expressed declaratively
|
||||
|
||||
#### Supported Platforms
|
||||
Rx 4.1 supports the following platforms
|
||||
Rx has been particularly successfully applied in user interfaces. (This is also true outside of .NET—[RxJS](https://rxjs.dev/) is a JavaScript spin-off of Rx, and it is very popular in user interface code.) The https://github.com/reactiveui/reactiveui makes deep use of Rx to support .NET UI development.
|
||||
|
||||
- .NET Framework 4.6+
|
||||
- .NET Standard 2.0+ (including .NET Core, Xamarin and others)
|
||||
- UWP
|
||||
To learn more, see this [Rx playlist](https://www.youtube.com/playlist?list=PLJt9xcgQpM60Fz20FIXBvj6ku4a7WOLGb).
|
||||
|
||||
Notably, Windows 8, Windows Phone 8 and legacy PCL libraries are no longer supported.
|
||||
## AsyncRx.Net
|
||||
|
||||
### v3.0 breaking changes
|
||||
The NuGet packages have changed their package naming in the move from v2.x.x to v3.0.0
|
||||
* ~~`Rx-Main`~~ is now [`System.Reactive`](https://www.nuget.org/packages/System.Reactive/)
|
||||
* ~~`Rx-Core`~~ is now [`System.Reactive.Core`](https://www.nuget.org/packages/System.Reactive.Core/)
|
||||
* ~~`Rx-Interfaces`~~ is now [`System.Reactive.Interfaces`](https://www.nuget.org/packages/System.Reactive.Interfaces/)
|
||||
* ~~`Rx-Linq`~~ is now [`System.Reactive.Linq`](https://www.nuget.org/packages/System.Reactive.Linq/)
|
||||
* ~~`Rx-PlatformServices`~~ is now [`System.Reactive.PlatformServices`](https://www.nuget.org/packages/System.Reactive.PlatformServices/)
|
||||
* ~~`Rx-Testing`~~ is now [`Microsoft.Reactive.Testing`](https://www.nuget.org/packages/Microsoft.Reactive.Testing/)
|
||||
Although Rx is a natural way to model asynchronous processes, its original design presumed that code acting on notifications would run synchronously. This is because Rx's design predates C#'s `async`/`await` language features. So although Rx offer adapters that can convert between [`IObservable<T>`](https://learn.microsoft.com/en-us/dotnet/api/system.iobservable-1) and [`Task<T>`](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1), there were certain cases where `async` was not an option.
|
||||
|
||||
This brings the NuGet package naming in line with NuGet guidelines and also the dominant namespace in each package.
|
||||
The strong name key has also changed, which is considered a breaking change.
|
||||
However, there are no expected API changes, therefore, once you make the NuGet change, no code changes should be necessary.
|
||||
AsyncRx.Net lifts this restriction by defining `IAsyncObservable<T>`. This enables observers to use asynchronous code. For example, if `bigTrades` were an `IAsyncObservable<Trade>` we could write this:
|
||||
|
||||
A Brief Intro
|
||||
-------------------
|
||||
```cs
|
||||
bigTrades.Subscribe(async t => await bigTradeStore.LogTradeAsync(t));
|
||||
```
|
||||
|
||||
The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. Using Rx, developers *__represent__* asynchronous data streams with [Observables](https://docs.microsoft.com/dotnet/api/system.iobservable-1), *__query__* asynchronous data streams using [LINQ operators](http://msdn.microsoft.com/en-us/library/hh242983.aspx), and *__parameterize__* the concurrency in the asynchronous data streams using [Schedulers](http://msdn.microsoft.com/en-us/library/hh242963.aspx). Simply put, Rx = Observables + LINQ + Schedulers.
|
||||
AsyncRx.Net is currently in preview.
|
||||
|
||||
Whether you are authoring a traditional desktop or web-based application, you have to deal with asynchronous and event-based programming from time to time. Desktop applications have I/O operations and computationally expensive tasks that might take a long time to complete and potentially block other active threads. Furthermore, handling exceptions, cancellation, and synchronization is difficult and error-prone.
|
||||
## Interactive Extensions
|
||||
|
||||
Using Rx, you can represent multiple asynchronous data streams (that come from diverse sources, e.g., stock quote, tweets, computer events, web service requests, etc.), and subscribe to the event stream using the `IObserver<T>` interface. The `IObservable<T>` interface notifies the subscribed `IObserver<T>` interface whenever an event occurs.
|
||||
Rx defines all the standard LINQ operators available for other providers, but it also adds numerous additional operators. For example, it defines `Scan`, which performs the same basic processing as the standard [`Aggregate`](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.aggregate) operator, but instead of producing a single result after processing every element, it produces a sequence containing the aggregated value after every single step. (For example, if the operation being aggregated is addition, `Aggregate` would return the sum total as a single output, whereas `Scan` would produce a running total for each input. Given a sequence `[1,2,3]`, `Aggregate((a, x) => a + x)` produces just `6`, whereas `Scan` would produce `[1,3,6]`.)
|
||||
|
||||
Because observable sequences are data streams, you can query them using standard LINQ query operators implemented by the Observable extension methods. Thus you can filter, project, aggregate, compose and perform time-based operations on multiple events easily by using these standard LINQ operators. In addition, there are a number of other reactive stream specific operators that allow powerful queries to be written. Cancellation, exceptions, and synchronization are also handled gracefully by using the extension methods provided by Rx.
|
||||
Some of the additional operators Rx defines are useful only when you're working with events. But some are applicable to sequences of any kind. So the Interactive Extensions (Ix for short) define implementations for `IEnumerable<T>`. Ix is effectively an extension of LINQ to Objects, adding numerous additional operators. (Its usefulness is borne out by the fact that the .NET runtime libraries have, over time, added some of the operators that used to be available only in Ix. For example, .NET 6 added [`MinBy`](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.minby) and [`MaxBy`](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.maxby), operators previously only defined by Ix.)
|
||||
|
||||
Rx complements and interoperates smoothly with both synchronous data streams (`IEnumerable<T>`) and single-value asynchronous computations (`Task<T>`) as the following diagram shows:
|
||||
This library is called the "Interactive Extensions" because "Interactive" is in a sense the opposite of "Reactive". (The name does not refer to user interactions.)
|
||||
|
||||
## LINQ for `IAsyncEnumerable` (`System.Linq.Async`)
|
||||
|
||||
One of the features pioneered by Ix was an asynchronous version of `IEnumerable<T>`. This is another example of a feature so useful that it was eventually added to the .NET runtime libraries: .NET Core 3.0 introduced [`IAsyncEnumerable<T>`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1), and the associated version C# (8.0) added intrinsic support for this interface with its `await foreach` construct.
|
||||
|
||||
Although .NET Core 3.0 defined `IAsyncEnumerable<T>`, it did not add any corresponding LINQ implementation. Whereas [`IEnumerable<T>` supports all the standard operators](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable) such as `Where`, `GroupBy`, and `SelectMany`, .NET does not have built-in implementations of any of these for `IAsyncEnumerable<T>`. However, Ix had provided LINQ operators for its prototype version of `IAsyncEnumerable<T>` from the start, so when .NET Core 3.0 shipped, it was a relatively straightforward task to update all those existing LINQ operators to work with the new, official [`IAsyncEnumerable<T>`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1).
|
||||
|
||||
Thus, the [System.Linq.Async](https://www.nuget.org/packages/System.Linq.Async/) NuGet package was created, providing a LINQ to Objects implementation for `IAsyncEnumerable<T>` to match the one already built into .NET for `IEnumerable<T>`.
|
||||
|
||||
Since all of the relevant code was already part of the Ix project (with `IAsyncEnumerable<T>` also originally having been defined by this project), the [System.Linq.Async](https://www.nuget.org/packages/System.Linq.Async/) NuGet package is built as part of the [Ix project](Ix.NET/).
|
||||
|
||||
|
||||
<table>
|
||||
<th></th><th>Single return value</th><th>Multiple return values</th>
|
||||
<tr>
|
||||
<td>Pull/Synchronous/Interactive</td>
|
||||
<td>T</td>
|
||||
<td>IEnumerable<T></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Push/Asynchronous/Reactive</td>
|
||||
<td>Task<T></td>
|
||||
<td>IObservable<T></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Additional documentation, video, tutorials and HOL are available on [MSDN](https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh242985(v=vs.103)), on [*Introduction to Rx*](http://introtorx.com/), [*ReactiveX*](http://reactivex.io/), and [ReactiveUI](https://reactiveui.net/).
|
||||
|
||||
Flavors of Rx
|
||||
---------------
|
||||
|
||||
* __Rx.NET__: *(this repository)* The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators.
|
||||
* [RxJS](https://github.com/ReactiveX/rxjs): The Reactive Extensions for JavaScript (RxJS) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in JavaScript which can target both the browser and Node.js.
|
||||
* [RxJava](https://github.com/ReactiveX/RxJava): Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
|
||||
* [RxScala](https://github.com/ReactiveX/RxScala): Reactive Extensions for Scala – a library for composing asynchronous and event-based programs using observable sequences
|
||||
* [RxCpp](https://github.com/Reactive-Extensions/RxCpp): The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C and C++.
|
||||
* [RxPy](https://github.com/ReactiveX/RxPY): The Reactive Extensions for Python 3 (Rx.Py) is a set of libraries to compose asynchronous and event-based programs using observable collections and LINQ-style query operators in Python 3.
|
||||
|
||||
|
||||
Interactive Extensions
|
||||
-----------------------
|
||||
* __Ix.NET__: *(included in this repository)* The Interactive Extensions (Ix) is a .NET library which extends LINQ to Objects to provide many of the operators available in Rx but targeted for IEnumerable<T>.
|
||||
* [IxJS](https://github.com/ReactiveX/IxJS): An implementation of LINQ to Objects and the Interactive Extensions (Ix) in JavaScript.
|
||||
* [IxCpp](https://github.com/Reactive-Extensions/RxCpp): An implementation of LINQ for Native Developers in C++
|
||||
|
||||
Applications
|
||||
-------------
|
||||
* [Tx](https://github.com/Reactive-Extensions/Tx): a set of code samples showing how to use LINQ to events, such as real-time standing queries and queries on past history from trace and log files, which targets ETW, Windows Event Logs and SQL Server Extended Events.
|
||||
* [LINQ2Charts](http://linq2charts.codeplex.com): an example for Rx bindings. Similar to existing APIs like LINQ to XML, it allows developers to use LINQ to create/change/update charts in an easy way and avoid having to deal with XML or other underneath data structures. We would love to see more Rx bindings like this one.
|
||||
|
||||
Contributing
|
||||
------------------
|
||||
|
||||
### Source code
|
||||
|
||||
* Clone the sources: `git clone https://github.com/dotnet/reactive`
|
||||
* [Building, testing and debugging the sources](https://github.com/dotnet/reactive/wiki/Building%20Testing%20and%20Debugging)
|
||||
|
||||
### Contribute!
|
||||
## Contributing
|
||||
|
||||
Some of the best ways to contribute are to try things out, file bugs, and join in design conversations.
|
||||
|
||||
* Clone the sources: `git clone https://github.com/dotnet/reactive`
|
||||
* [Building, testing and debugging the sources](https://github.com/dotnet/reactive/wiki/Building%20Testing%20and%20Debugging)
|
||||
* [How to Contribute](https://github.com/dotnet/reactive/wiki/Contributing-Code)
|
||||
* [Pull requests](https://github.com/dotnet/reactive/pulls): [Open](https://github.com/dotnet/reactive/pulls?q=is%3Aopen+is%3Apr)/[Closed](https://github.com/dotnet/reactive/pulls?q=is%3Apr+is%3Aclosed)
|
||||
|
||||
|
@ -138,39 +107,39 @@ Looking for something to work on? The list of [up for grabs issues](https://gith
|
|||
|
||||
This project has adopted a code of conduct adapted from the [Contributor Covenant](http://contributor-covenant.org/) to clarify expected behavior in our community. This code of conduct has been [adopted by many other projects](http://contributor-covenant.org/adopters/). For more information see the [Code of conduct](http://www.dotnetfoundation.org/code-of-conduct).
|
||||
|
||||
<h2 align="center">.NET Foundation</h2>
|
||||
## .NET Foundation
|
||||
|
||||
System.Reactive is part of the [.NET Foundation](https://www.dotnetfoundation.org/). Other projects that are associated with the foundation include the Microsoft .NET Compiler Platform ("Roslyn") as well as the Microsoft ASP.NET family of projects, Microsoft .NET Core & Xamarin Forms.
|
||||
This project is part of the [.NET Foundation](http://www.dotnetfoundation.org/projects) along with other
|
||||
projects like [the .NET Runtime](https://github.com/dotnet/runtime/). The .NET Foundation provides this project with DevOps infrastructure to compile, test, sign and package this complex solution which has over 100 million downloads. It also provides conservatorship enabling the project to pass from maintainer to maintainer, enabling continuity for the community.
|
||||
|
||||
<h2 align="center">Core Team</h2>
|
||||
## Current Core Team
|
||||
|
||||
The people currently maintaining Rx are:
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="top">
|
||||
<img width="150" height="150" src="https://github.com/ghuntley.png?s=150">
|
||||
<img width="150" height="150" src="https://github.com/idg10.png?s=150">
|
||||
<br>
|
||||
<a href="https://github.com/ghuntley">Geoffrey Huntley</a>
|
||||
<p>Sydney, Australia</p>
|
||||
<a href="https://github.com/idg10">Ian Griffiths</a>
|
||||
<p>Hove, UK</p>
|
||||
<p><a href="https://endjin.com/who-we-are/our-people/ian-griffiths/">Ian's blog on endjin.com</a>
|
||||
</td>
|
||||
<td align="center" valign="top">
|
||||
<img width="150" height="150" src="https://github.com/clairernovotny.png?s=150">
|
||||
<img width="150" height="150" src="https://github.com/HowardvanRooijen.png?s=150">
|
||||
<br>
|
||||
<a href="https://github.com/clairernovotny">Claire Novotny</a>
|
||||
<p>New York, USA</p>
|
||||
<a href="https://github.com/HowardvanRooijen">Howard van Rooijen</a>
|
||||
<p>Winchester, UK</p>
|
||||
<p><a href="https://endjin.com/who-we-are/our-people/howard-van-rooijen/">Howard's blog on endjin.com</a>
|
||||
</td>
|
||||
<td align="center" valign="top">
|
||||
<img width="150" height="150" src="https://github.com/akarnokd.png?s=150">
|
||||
<br>
|
||||
<a href="https://github.com/akarnokd">David Karnok</a>
|
||||
<p>Budapest, Hungary</p>
|
||||
</td>
|
||||
<td align="center" valign="top">
|
||||
<img width="150" height="150" src="https://github.com/danielcweber.png?s=150">
|
||||
<br>
|
||||
<a href="https://github.com/danielcweber">Daniel C. Weber</a>
|
||||
<p>Aachen, Germany</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Rx has been around for roughly a decade and a half, so we owe a great deal to its creators, and the many people who have worked on it since. See the [AUTHORS.txt](AUTHORS.txt) for a full list.
|
||||
|
||||
## Roadmap
|
||||
|
||||
We have set out a [roadmap](Rx.NET/Documentation/Rx-Roadmap-2023.md) explaining our medium term plans for ongoing development of Rx. This diagram illustrates our view of the platforms on which Rx is used, and the planned support lifecycles for these various targets:
|
||||
|
||||
![The support lifecycle for various .NET platforms, represented as a set of timelines, showing the published plans for widely used versions that are current as of 2023, with a particular focus on which versions will be current as of November 2023. The top section of the diagram shows .NET releases starting with .NET 6.0 being released in November 2021, and shows for each subsequent release occurring in November of each subsequent year, up as far as .NET 13.0 in November 2028. It also shows that even-numbered releases are Long Term Support (LTS for short) releases, supported for 3 years, while odd-numbered releases are supported only for 18 months. The section beneath this shows that .NET Framework versions 4.7.2, 4.8.0, and 4.8.1 will all be in support as of November 2023, and will continue to be in support beyond the timescale covered by this diagram, i.e., beyond November 2028. The section beneath this shows the release plan for MAUI, starting with version 8.0 on November 2023, and subsequent releases at the same time each subsequent year, up to version 13.0 in November 2028. The diagram shows that each of these versions is supported for only 18 months. Beneath this is are two lines showing Xamarin iOS 16.0, and Xamarin Android 13.0 support being active on November 2023, and running for 18 months. Beneath this is a line showing UWP version 10.0.16299 support being active on November 2023, and running beyond the timescale covered by the diagram. Beneath this is a section showing that Unity 2021 was released in 2021, and will go out of support near the end of 2023, and it shows a Unity 2022 release labelled as "Release soon," with a release date somewhere in the middle of 2023. The bottom of the diagram shows the endjin logo, and endjin's corporate motto: "we help small teams achieve big things."](Rx.NET/Documentation/RX-Platform-Support-Roadmap.png ".NET Platform Support Roadmap")
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
# Rx Release History v5.0 and Older
|
||||
|
||||
## v5.0 changes
|
||||
|
||||
Rx.NET v5 is required for .NET 5 support of CSWinRT; earlier versions of Rx won't work correctly. To get the Windows API, you need to use the latest Windows SDK (19041), though you can target earlier versions of Windows.
|
||||
|
||||
**Breaking changes**
|
||||
In Windows, since the `net5.0-windows10.0.19041` target now supports all Windows desktop object models, on UWP `DispatcherObservable` and releated SubscribeOn/ObserveOn were renamed to be `CoreDispatcherObservable`, `SubscribeOnCoreDispatcher`, and `ObserveOnCoreDispatcher`. This reflects the OS type names. `Dispatcher` refers only to the WPF type.
|
||||
|
||||
### Supported Platforms
|
||||
Rx 5.x supports the following platforms
|
||||
|
||||
- .NET 5
|
||||
- .NET 5 with the Windows 10 19041 SDK (able to target earlier Windows versions)
|
||||
- .NET Framework 4.7
|
||||
- UWP 10.0.16299
|
||||
- .NET Standard 2.0
|
||||
|
||||
Support for older versions of UWP 10.0 has been removed.
|
||||
|
||||
## v4.0 changes
|
||||
|
||||
Due to the [overwhelming](https://github.com/dotnet/reactive/issues/299) [pain](https://github.com/dotnet/reactive/issues/305) that fixing [#205 - Implement assembly version strategy](https://github.com/dotnet/reactive/issues/205) caused, we have refactored the libraries into a single library `System.Reactive`. To prevent breaking existing code that references the v3 libraries, we have facades with TypeForwarders to the new assembly. If you have a reference to a binary built against v3.0, then use the new `System.Reactive.Compatibility` package.
|
||||
|
||||
#### Supported Platforms
|
||||
Rx 4.1 supports the following platforms
|
||||
|
||||
- .NET Framework 4.6+
|
||||
- .NET Standard 2.0+ (including .NET Core, Xamarin and others)
|
||||
- UWP
|
||||
|
||||
Notably, Windows 8, Windows Phone 8 and legacy PCL libraries are no longer supported.
|
||||
|
||||
## v3.0 breaking changes
|
||||
The NuGet packages have changed their package naming in the move from v2.x.x to v3.0.0
|
||||
* ~~`Rx-Main`~~ is now [`System.Reactive`](https://www.nuget.org/packages/System.Reactive/)
|
||||
* ~~`Rx-Core`~~ is now [`System.Reactive.Core`](https://www.nuget.org/packages/System.Reactive.Core/)
|
||||
* ~~`Rx-Interfaces`~~ is now [`System.Reactive.Interfaces`](https://www.nuget.org/packages/System.Reactive.Interfaces/)
|
||||
* ~~`Rx-Linq`~~ is now [`System.Reactive.Linq`](https://www.nuget.org/packages/System.Reactive.Linq/)
|
||||
* ~~`Rx-PlatformServices`~~ is now [`System.Reactive.PlatformServices`](https://www.nuget.org/packages/System.Reactive.PlatformServices/)
|
||||
* ~~`Rx-Testing`~~ is now [`Microsoft.Reactive.Testing`](https://www.nuget.org/packages/Microsoft.Reactive.Testing/)
|
||||
|
||||
This brings the NuGet package naming in line with NuGet guidelines and also the dominant namespace in each package.
|
||||
The strong name key has also changed, which is considered a breaking change.
|
||||
However, there are no expected API changes, therefore, once you make the NuGet change, no code changes should be necessary.
|
|
@ -0,0 +1,13 @@
|
|||
# Rx Release History v6.0
|
||||
|
||||
## v6.0.0-preview
|
||||
|
||||
### Breaking changes
|
||||
|
||||
* Out-of-support target frameworks (.NET Core 3.1, .NET 5) removed
|
||||
|
||||
### New features
|
||||
|
||||
* Tested against .NET 6, and .NET 7
|
||||
* When unhandled exceptions from `Task` used to cause `TaskScheduler.UnobservedExceptions`, applications can opt into swallowing failures silently (to be consistent with how Rx has always handled unhandled exceptions in the equivalent non-Task-oriented scenarios; this only applies to cases in which Rx has no way of reporting the exception, typically because the relevant observable no longer has any subscribers on which we could call `OnError`)
|
||||
* `SingleAssignmentDisposableValue` type is now public
|
|
@ -4,7 +4,7 @@
|
|||
<MinClientVersion>2.12</MinClientVersion>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<Authors>.NET Foundation and Contributors</Authors>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/dotnet/reactive/0f837d11385cfaf575861ccc5a5fbcafb22d888f/Rx.NET/Resources/Artwork/Logo.png</PackageIconUrl>
|
||||
<PackageIcon>icon.png</PackageIcon>
|
||||
<PackageProjectUrl>https://github.com/dotnet/reactive</PackageProjectUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
@ -33,10 +33,19 @@
|
|||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
|
||||
|
||||
<!--
|
||||
Nerdbank.GitVersioning 3.6.128 injects a reference to a .proj file that doesn't work inside UWP projects,
|
||||
so we make this conditional so it doesn't appear in the test runner.
|
||||
Nerdbank.GitVersioning 3.6.128 injects a reference to a .proj file that doesn't work inside the
|
||||
UWP test runner project. We don't ship that as a NuGet package, so it doesn't matter what its
|
||||
version number is.
|
||||
-->
|
||||
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.128" PrivateAssets="all" Condition="$(TargetPlatformIdentifier) != 'UAP'" />
|
||||
<PackageReference
|
||||
Include="Nerdbank.GitVersioning"
|
||||
Version="3.6.128"
|
||||
PrivateAssets="all"
|
||||
Condition="$(ProjectName) != 'Tests.System.Reactive.Uwp.DeviceRunner'" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="$(MSBuildThisFileDirectory)../Resources/Artwork/Logo.png" Pack="true" PackagePath="\icon.png"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# Legacy facade package for `System.Reactive`
|
||||
|
||||
This package exists for backwards compatibility, and should not be used by new applications. Older versions of the Reactive Extensions for .NET (Rx) split types across various packages including this one.
|
||||
|
||||
Most applications using Rx today should reference `System.Reactive` directly.
|
|
@ -11,6 +11,7 @@
|
|||
<iconUrl>http://go.microsoft.com/fwlink/?LinkId=261274</iconUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>Reactive Extensions (Rx) Compatibility Library for enabling v3 apps to work with v4</description>
|
||||
<readme>readme.md</readme>
|
||||
<copyright>Copyright (c) .NET Foundation and Contributors.</copyright>
|
||||
<language>en-US</language>
|
||||
<tags>Rx Reactive Extensions</tags>
|
||||
|
@ -44,5 +45,7 @@
|
|||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files />
|
||||
<files>
|
||||
<file src="NuGet.Facades.Readme.md" target="\readme.md"/>
|
||||
</files>
|
||||
</package>
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
<TargetFrameworks>net472;netstandard2.0;uap10.0.18362</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Legacy facade for Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\NuGet.Facades.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
<TargetFrameworks>net472</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Legacy facade for Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\NuGet.Facades.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
<TargetFrameworks>net472;netstandard2.0;uap10.0.18362</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Legacy facade for Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\NuGet.Facades.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
<TargetFrameworks>net472;netstandard2.0;uap10.0.18362</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Legacy facade for Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\NuGet.Facades.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
<TargetFrameworks>net472;netstandard2.0;uap10.0.18362</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Legacy facade for Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\NuGet.Facades.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
<TargetFrameworks>net472;netstandard2.0;uap10.0.18362</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Legacy facade for Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\NuGet.Facades.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
<TargetFramework>net472</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Legacy facade for Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\NuGet.Facades.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
<TargetFrameworks>net472</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Legacy facade for Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\NuGet.Facades.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
<TargetFrameworks>net472;uap10.0.18362</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Legacy facade for Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\NuGet.Facades.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
<TargetFramework>uap10.0.18362</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Legacy facade for Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\NuGet.Facades.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<DefineConstants>$(DefineConstants);PLATFORM_DOTNET;XUNIT_VISIBILITY_INTERNAL</DefineConstants>
|
||||
<PackageTags>Rx;Reactive;Extensions;Observable;LINQ;Events</PackageTags>
|
||||
<Description>Reactive Extensions (Rx) for .NET - Testing Library</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
<!-- NB: A lot of CA and IDE warnings are disabled because of the .cs files included from xunit.assert.source. -->
|
||||
<NoWarn>$(NoWarn);IDE0054;IDE0066;CA1305;CA1307;CA1032;CA1064;CA1704;CA1822;CA1812;CA1820;CA1823;CA1825;CA1845;CA2249;IDE0016;IDE0018;IDE0019;IDE0020;IDE0031;IDE0039;IDE0044;IDE0059;IDE0074;IDE0270</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
@ -22,6 +23,8 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="build\NuGet.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
|
||||
<!--
|
||||
Workaround for https://github.com/xunit/xunit/issues/2703
|
||||
-->
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# Testing utilities for Rx (Reactive Extensions for .NET)
|
||||
|
||||
This package is mainly designed for internal use in the https://github.com/dotnet/reactive repository. It enables virtual-time-based testing of Rx operators, so it may be useful to libraries defining their own custom Rx operators, which is why it is published as a NuGet package. However, its use is currently unsupported, and there is no commitment to backwards compatibility.
|
|
@ -5,6 +5,7 @@
|
|||
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
|
||||
<PackageTags>Rx;Reactive;Extensions;Observable;LINQ;Events</PackageTags>
|
||||
<Description>Reactive Extensions (Rx) provides the aliases Map, FlatMap, and Filter</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\AssemblyInfo.cs" Link="Properties\AssemblyInfo.cs" />
|
||||
|
@ -12,4 +13,8 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\System.Reactive\System.Reactive.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="build\NuGet.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,7 @@
|
|||
# Aliases for certain Rx operators
|
||||
|
||||
Rx uses the standard LINQ names for its operators. This package enables applications that wish to to use certain names common in other programming systems. Specifically:
|
||||
|
||||
* `Map` (`Select`)
|
||||
* `FlatMap` (`SelectMany`)
|
||||
* `Filter` (`Where`)
|
|
@ -4,6 +4,7 @@
|
|||
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
|
||||
<PackageTags>Rx;Reactive;Extensions;Observable;LINQ;Events</PackageTags>
|
||||
<Description>Reactive Extensions (Rx) for .NET</Description>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
@ -149,6 +150,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="build\NuGet.Readme.md" Pack="true" PackagePath="\readme.md"/>
|
||||
<None Include="build\_._" PackagePath="build\net6.0;build\net6.0-windows10.0.19041" Pack="true" />
|
||||
<None Include="build\_._" PackagePath="buildTransitive\net6.0;buildTransitive\net6.0-windows10.0.19041" Pack="true" />
|
||||
<None Include="Linq\QbservableEx.NAry.cs">
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
# Rx (Reactive Extensions for .NET)
|
||||
|
||||
Rx enables event-driven programming with a composable, declarative model.
|
||||
|
||||
|
||||
## Getting started
|
||||
|
||||
Run the following at a command line:
|
||||
|
||||
```ps1
|
||||
mkdir TryRx
|
||||
cd TryRx
|
||||
dotnet new console
|
||||
dotnet add package System.Reactive
|
||||
```
|
||||
|
||||
Alternatively, if you have Visual Studio installed, create a new .NET Console project, and then use the NuGet package manager to add a reference to `System.Reactive`.
|
||||
|
||||
You can then add this code to your `Program.cs`. This creates an observable source (`ticks`) that produces an event once every second. It also adds a handler to that source that writes a message to the console for each event:
|
||||
|
||||
```cs
|
||||
using System.Reactive.Linq;
|
||||
|
||||
IObservable<long> ticks = Observable.Timer(
|
||||
dueTime: TimeSpan.Zero,
|
||||
period: TimeSpan.FromSeconds(1));
|
||||
|
||||
ticks.Subscribe(
|
||||
tick => Console.WriteLine($"Tick {tick}"));
|
||||
|
||||
Console.ReadLine();
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Wrapping an existing event source as an Rx `IObservable<T>`
|
||||
|
||||
If you have an existing source of events that does not support Rx directly, but which does offer .NET events, you can bring this into the world of Rx using the `Observable.FromEventPattern` method:
|
||||
|
||||
```cs
|
||||
using System.Reactive.Linq;
|
||||
|
||||
FileSystemWatcher fsw = new FileSystemWatcher(@"C:\temp");
|
||||
|
||||
IObservable<FileSystemEventArgs> changeEvents = Observable
|
||||
.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(
|
||||
h => fsw.Changed += h,
|
||||
h => fsw.Changed -= h)
|
||||
.Select(e => e.EventArgs);
|
||||
|
||||
fsw.EnableRaisingEvents = true;
|
||||
```
|
||||
|
||||
|
||||
### Waiting for inactivity
|
||||
|
||||
It can sometimes be useful to wait for a period of inactivity before taking action. For example, if you have code that monitors a directory in a filesystem, processing modified or added files, it's common for there to be flurries of activity. For example, if a user is copying multiple files into a folder that you're observing, there will be multiple changes, and it could be more efficient to wait until those stop and then process all the changes in one batch, than to attempt to process everything immediately.
|
||||
|
||||
This example defines a custom Rx operator that can be attached to any source. It will wait for that source to start producing events, and then, it will wait for it to stop again for the specified period. Each time that happens, it reports all of the activity that occurred between the last two periods of inactivity:
|
||||
|
||||
```cs
|
||||
static class RxExt
|
||||
{
|
||||
public static IObservable<IList<T>> Quiescent<T>(
|
||||
this IObservable<T> src,
|
||||
TimeSpan minimumInactivityPeriod,
|
||||
IScheduler scheduler)
|
||||
{
|
||||
IObservable<int> onoffs =
|
||||
from _ in src
|
||||
from delta in Observable.Return(1, scheduler).Concat(Observable.Return(-1, scheduler).Delay(minimumInactivityPeriod, scheduler))
|
||||
select delta;
|
||||
IObservable<int> outstanding = onoffs.Scan(0, (total, delta) => total + delta);
|
||||
IObservable<int> zeroCrossings = outstanding.Where(total => total == 0);
|
||||
return src.Buffer(zeroCrossings);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
(This works by creating a sequence (`onoffs`) that produces a value 1 each time activity occurs, and then a corresponding -1 after the specified time has elapsed. It then uses `Scan` to produce the `outstanding` sequence, which is just a running total of those `onoffs`. This is effectively a count of the number of events that have happened recently (where 'recently' is defined as 'less than `minimumInactivityPeriod` ago). Every new event that occurs raises this running total by 1, but each time the specified timespan has passed for a particular event, it drops by one. So when this drops back to 0, it means that there are no events that have occurred as recently as the `minimumInactivityPeriod`. The `zeroCrossings` sequence picks out just the events in which `outstanding` drops back to zero. This has the effect that `zeroCrossings` raises an event every time there has been some activity followed by `minimumInactivityPeriod` of inactivity. Finally, we plug this into the `Buffer` operator, which slices the input events (`src`) into chunks. By passing it the `zeroCrossings` source, we tell `Buffer` to deliver a new slice every time the source becomes inactive. The effect is that the source returned by `Quiescent` does nothing until there has been some activity followed by the specified period of inactivity, at which point it produces a single event reporting all of the source events that have occurred since the previous period, or in the initial case, all of the source events so far.)
|
||||
|
||||
You could use this in conjunction with the adapted `FileSystemWatcher` from the preceding example:
|
||||
|
||||
```cs
|
||||
IObservable<IList<FileSystemEventArgs>> fileActivityStopped = changeEvents
|
||||
.Quiescent(TimeSpan.FromSeconds(2), Scheduler.Default);
|
||||
|
||||
await fileActivityStopped.ForEachAsync(
|
||||
a => Console.WriteLine($"File changes stopped after {a.Count} changes"));
|
||||
```
|
||||
|
||||
(Note: this only uses the `Changed` event. A real application might also need to look at the `FileSystemWatcher`'s `Created`, `Renamed`, and `Deleted` events.)
|
||||
|
||||
## Feedback
|
||||
|
||||
You can create issues at the https://github.com/dotnet/reactive repository
|
Загрузка…
Ссылка в новой задаче