diff --git a/.gitignore b/.gitignore index ea10192e2a..c3770d83d4 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/AUTHORS.txt b/AUTHORS.txt index c8966f922a..a55dfbab6e 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -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 diff --git a/Ix.NET/Documentation/Museum/OldReadme.md b/Ix.NET/Documentation/Museum/OldReadme.md new file mode 100644 index 0000000000..74c8b6e650 --- /dev/null +++ b/Ix.NET/Documentation/Museum/OldReadme.md @@ -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` interface. The `IObservable` interface notifies the subscribed `IObserver` 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`) and single-value asynchronous computations (`Task`) as the following diagram shows: + + + + + + + + + + + + + + +
Single return valueMultiple return values
Pull/Synchronous/InteractiveTIEnumerable<T>
Push/Asynchronous/ReactiveTask<T>IObservable<T>
+ +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. diff --git a/Ix.NET/Documentation/ReleaseHistory/Ix.v5-and-before.md b/Ix.NET/Documentation/ReleaseHistory/Ix.v5-and-before.md new file mode 100644 index 0000000000..26a6671fc0 --- /dev/null +++ b/Ix.NET/Documentation/ReleaseHistory/Ix.v5-and-before.md @@ -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`, the Ix.NET project also includes `System.Linq.Async`, which defines for `IAsyncEnumerable` the same LINQ operators that are built into the .NET runtime libraries for `IEnumerable`. + +## V5.1 + +Removed various `IEnumerable` 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` 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` 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`. 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`. Whereas `IEnumerable` 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`. 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`, v4.0 of Ix also builds the `System.Linq.Async` library, making LINQ to Objects available for `IAsyncEnumerable`. \ No newline at end of file diff --git a/Ix.NET/Documentation/ReleaseHistory/Ix.v6.md b/Ix.NET/Documentation/ReleaseHistory/Ix.v6.md new file mode 100644 index 0000000000..49ea8e79e0 --- /dev/null +++ b/Ix.NET/Documentation/ReleaseHistory/Ix.v6.md @@ -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.) + diff --git a/README.md b/README.md index 8a137c846e..9c43230781 100644 --- a/README.md +++ b/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
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: -### Join the conversation +* [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` 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` -Catch us in the #rxnet channel over at http://reactiveui.net/slack +Each will be described later in this README. -### Get nightly builds -- NuGet v3 feed url (VS 2015+): `https://pkgs.dev.azure.com/dotnet/Rx.NET/_packaging/RxNet/nuget/v3/index.json` +## Getting the bits -## System.Linq.Async / System.Interactive.Async / System.Interactive +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
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/) -### v4.0 changes +For nightly builds, configure NuGet to use this feed: `https://pkgs.dev.azure.com/dotnet/Rx.NET/_packaging/RxNet/nuget/v3/index.json` -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` 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. +### Join the conversation -There are many breaking changes here; a full set of changenotes is on the way. +Catch us in the #rxnet channel over at http://reactiveui.net/slack -## System.Reactive -### 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. +## A Brief Introduction to Rx -**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. +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. -#### Supported Platforms -Rx 5.x supports the following platforms +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. -- .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 +Rx elevates the support for live streams of information to the same level as we expect for things like arrays. Here's an example: -Support for UWP 10.0 has been removed. +```cs +var bigTrades = + from trade in trades + where trade.Volume > 1_000_000; +``` -### 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. +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: -#### Supported Platforms -Rx 4.1 supports the following platforms +```cs +var bigTrades = trades.Where(trade => trade.Volume > 1_000_000); +``` -- .NET Framework 4.6+ -- .NET Standard 2.0+ (including .NET Core, Xamarin and others) -- UWP +The exact behaviour of these two (equivalent) code snippets depends on what type `trades` has. If it were a `IEnumerable`, 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`, an object reporting live events as they happen. And `bigTrades` would also be an `IObservable`, 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: -Notably, Windows 8, Windows Phone 8 and legacy PCL libraries are no longer supported. +```cs +bigTrades.Subscribe(t => Console.WriteLine($"{t.Symbol}: trade with volume {t.Volume}")); +``` -### 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/) +The two key features of Rx are: -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. +* a clearly defined way to represent and handle live sequences of data ([`IObservable`](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 -A Brief Intro -------------------- +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. -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. +To learn more, see this [Rx playlist](https://www.youtube.com/playlist?list=PLJt9xcgQpM60Fz20FIXBvj6ku4a7WOLGb). -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. +## AsyncRx.Net -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` interface. The `IObservable` interface notifies the subscribed `IObserver` interface whenever an event occurs. +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`](https://learn.microsoft.com/en-us/dotnet/api/system.iobservable-1) and [`Task`](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1), there were certain cases where `async` was not an option. -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. +AsyncRx.Net lifts this restriction by defining `IAsyncObservable`. This enables observers to use asynchronous code. For example, if `bigTrades` were an `IAsyncObservable` we could write this: -Rx complements and interoperates smoothly with both synchronous data streams (`IEnumerable`) and single-value asynchronous computations (`Task`) as the following diagram shows: +```cs +bigTrades.Subscribe(async t => await bigTradeStore.LogTradeAsync(t)); +``` +AsyncRx.Net is currently in preview. - - - - - - - - - - - - -
Single return valueMultiple return values
Pull/Synchronous/InteractiveTIEnumerable<T>
Push/Asynchronous/ReactiveTask<T>IObservable<T>
+## Interactive Extensions -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/). +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]`.) -Flavors of 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`. 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.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. +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`) -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. -* [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++ +One of the features pioneered by Ix was an asynchronous version of `IEnumerable`. 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`](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. -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. +Although .NET Core 3.0 defined `IAsyncEnumerable`, it did not add any corresponding LINQ implementation. Whereas [`IEnumerable` 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`. However, Ix had provided LINQ operators for its prototype version of `IAsyncEnumerable` 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`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1). -Contributing ------------------- +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` to match the one already built into .NET for `IEnumerable`. + +Since all of the relevant code was already part of the Ix project (with `IAsyncEnumerable` 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/). -### 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). -

.NET Foundation

+## .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. -

Core Team

+## Current Core Team + +The people currently maintaining Rx are: - - -
- -
- Geoffrey Huntley -

Sydney, Australia

-
- +
- Claire Novotny -

New York, USA

+ Ian Griffiths +

Hove, UK

+

Ian's blog on endjin.com

- +
- David Karnok -

Budapest, Hungary

+ Howard van Rooijen +

Winchester, UK

+

Howard's blog on endjin.com

- -
- Daniel C. Weber -

Aachen, Germany

-
+ +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") diff --git a/Rx.NET/Documentation/ReleaseHistory/Rx.v5-and-before.md b/Rx.NET/Documentation/ReleaseHistory/Rx.v5-and-before.md new file mode 100644 index 0000000000..bdb966383a --- /dev/null +++ b/Rx.NET/Documentation/ReleaseHistory/Rx.v5-and-before.md @@ -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. diff --git a/Rx.NET/Documentation/ReleaseHistory/Rx.v6.md b/Rx.NET/Documentation/ReleaseHistory/Rx.v6.md new file mode 100644 index 0000000000..e2b13b7411 --- /dev/null +++ b/Rx.NET/Documentation/ReleaseHistory/Rx.v6.md @@ -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 \ No newline at end of file diff --git a/Rx.NET/Source/Directory.build.props b/Rx.NET/Source/Directory.build.props index 4fcc83cf19..5861aeefb9 100644 --- a/Rx.NET/Source/Directory.build.props +++ b/Rx.NET/Source/Directory.build.props @@ -4,7 +4,7 @@ 2.12 true .NET Foundation and Contributors - https://raw.githubusercontent.com/dotnet/reactive/0f837d11385cfaf575861ccc5a5fbcafb22d888f/Rx.NET/Resources/Artwork/Logo.png + icon.png https://github.com/dotnet/reactive MIT true @@ -33,10 +33,19 @@ - + + + + + diff --git a/Rx.NET/Source/facades/NuGet.Facades.Readme.md b/Rx.NET/Source/facades/NuGet.Facades.Readme.md new file mode 100644 index 0000000000..e358c724db --- /dev/null +++ b/Rx.NET/Source/facades/NuGet.Facades.Readme.md @@ -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. \ No newline at end of file diff --git a/Rx.NET/Source/facades/System.Reactive.Compatibility.nuspec b/Rx.NET/Source/facades/System.Reactive.Compatibility.nuspec index 69637ffe04..89f4e542de 100644 --- a/Rx.NET/Source/facades/System.Reactive.Compatibility.nuspec +++ b/Rx.NET/Source/facades/System.Reactive.Compatibility.nuspec @@ -11,6 +11,7 @@ http://go.microsoft.com/fwlink/?LinkId=261274 false Reactive Extensions (Rx) Compatibility Library for enabling v3 apps to work with v4 + readme.md Copyright (c) .NET Foundation and Contributors. en-US Rx Reactive Extensions @@ -44,5 +45,7 @@ - + + + diff --git a/Rx.NET/Source/facades/System.Reactive.Core/System.Reactive.Core.csproj b/Rx.NET/Source/facades/System.Reactive.Core/System.Reactive.Core.csproj index b6f620e680..2da96f58f9 100644 --- a/Rx.NET/Source/facades/System.Reactive.Core/System.Reactive.Core.csproj +++ b/Rx.NET/Source/facades/System.Reactive.Core/System.Reactive.Core.csproj @@ -4,6 +4,15 @@ net472;netstandard2.0;uap10.0.18362 + + Legacy facade for Reactive Extensions (Rx) for .NET + readme.md + + + + + + diff --git a/Rx.NET/Source/facades/System.Reactive.Experimental/System.Reactive.Experimental.csproj b/Rx.NET/Source/facades/System.Reactive.Experimental/System.Reactive.Experimental.csproj index 294b589127..ac2d9f9a8f 100644 --- a/Rx.NET/Source/facades/System.Reactive.Experimental/System.Reactive.Experimental.csproj +++ b/Rx.NET/Source/facades/System.Reactive.Experimental/System.Reactive.Experimental.csproj @@ -4,6 +4,15 @@ net472 + + Legacy facade for Reactive Extensions (Rx) for .NET + readme.md + + + + + + diff --git a/Rx.NET/Source/facades/System.Reactive.Interfaces/System.Reactive.Interfaces.csproj b/Rx.NET/Source/facades/System.Reactive.Interfaces/System.Reactive.Interfaces.csproj index b6f620e680..2da96f58f9 100644 --- a/Rx.NET/Source/facades/System.Reactive.Interfaces/System.Reactive.Interfaces.csproj +++ b/Rx.NET/Source/facades/System.Reactive.Interfaces/System.Reactive.Interfaces.csproj @@ -4,6 +4,15 @@ net472;netstandard2.0;uap10.0.18362 + + Legacy facade for Reactive Extensions (Rx) for .NET + readme.md + + + + + + diff --git a/Rx.NET/Source/facades/System.Reactive.Linq/System.Reactive.Linq.csproj b/Rx.NET/Source/facades/System.Reactive.Linq/System.Reactive.Linq.csproj index b6f620e680..2da96f58f9 100644 --- a/Rx.NET/Source/facades/System.Reactive.Linq/System.Reactive.Linq.csproj +++ b/Rx.NET/Source/facades/System.Reactive.Linq/System.Reactive.Linq.csproj @@ -4,6 +4,15 @@ net472;netstandard2.0;uap10.0.18362 + + Legacy facade for Reactive Extensions (Rx) for .NET + readme.md + + + + + + diff --git a/Rx.NET/Source/facades/System.Reactive.PlatformServices/System.Reactive.PlatformServices.csproj b/Rx.NET/Source/facades/System.Reactive.PlatformServices/System.Reactive.PlatformServices.csproj index b6f620e680..2da96f58f9 100644 --- a/Rx.NET/Source/facades/System.Reactive.PlatformServices/System.Reactive.PlatformServices.csproj +++ b/Rx.NET/Source/facades/System.Reactive.PlatformServices/System.Reactive.PlatformServices.csproj @@ -4,6 +4,15 @@ net472;netstandard2.0;uap10.0.18362 + + Legacy facade for Reactive Extensions (Rx) for .NET + readme.md + + + + + + diff --git a/Rx.NET/Source/facades/System.Reactive.Providers/System.Reactive.Providers.csproj b/Rx.NET/Source/facades/System.Reactive.Providers/System.Reactive.Providers.csproj index b6f620e680..2da96f58f9 100644 --- a/Rx.NET/Source/facades/System.Reactive.Providers/System.Reactive.Providers.csproj +++ b/Rx.NET/Source/facades/System.Reactive.Providers/System.Reactive.Providers.csproj @@ -4,6 +4,15 @@ net472;netstandard2.0;uap10.0.18362 + + Legacy facade for Reactive Extensions (Rx) for .NET + readme.md + + + + + + diff --git a/Rx.NET/Source/facades/System.Reactive.Runtime.Remoting/System.Reactive.Runtime.Remoting.csproj b/Rx.NET/Source/facades/System.Reactive.Runtime.Remoting/System.Reactive.Runtime.Remoting.csproj index 9832f03011..9cc9b36b9c 100644 --- a/Rx.NET/Source/facades/System.Reactive.Runtime.Remoting/System.Reactive.Runtime.Remoting.csproj +++ b/Rx.NET/Source/facades/System.Reactive.Runtime.Remoting/System.Reactive.Runtime.Remoting.csproj @@ -4,6 +4,15 @@ net472 + + Legacy facade for Reactive Extensions (Rx) for .NET + readme.md + + + + + + diff --git a/Rx.NET/Source/facades/System.Reactive.Windows.Forms/System.Reactive.Windows.Forms.csproj b/Rx.NET/Source/facades/System.Reactive.Windows.Forms/System.Reactive.Windows.Forms.csproj index 294b589127..ac2d9f9a8f 100644 --- a/Rx.NET/Source/facades/System.Reactive.Windows.Forms/System.Reactive.Windows.Forms.csproj +++ b/Rx.NET/Source/facades/System.Reactive.Windows.Forms/System.Reactive.Windows.Forms.csproj @@ -4,6 +4,15 @@ net472 + + Legacy facade for Reactive Extensions (Rx) for .NET + readme.md + + + + + + diff --git a/Rx.NET/Source/facades/System.Reactive.Windows.Threading/System.Reactive.Windows.Threading.csproj b/Rx.NET/Source/facades/System.Reactive.Windows.Threading/System.Reactive.Windows.Threading.csproj index 366145a8c4..583c8ac48c 100644 --- a/Rx.NET/Source/facades/System.Reactive.Windows.Threading/System.Reactive.Windows.Threading.csproj +++ b/Rx.NET/Source/facades/System.Reactive.Windows.Threading/System.Reactive.Windows.Threading.csproj @@ -4,6 +4,15 @@ net472;uap10.0.18362 + + Legacy facade for Reactive Extensions (Rx) for .NET + readme.md + + + + + + diff --git a/Rx.NET/Source/facades/System.Reactive.WindowsRuntime/System.Reactive.WindowsRuntime.csproj b/Rx.NET/Source/facades/System.Reactive.WindowsRuntime/System.Reactive.WindowsRuntime.csproj index 0be1f2b00e..870c379991 100644 --- a/Rx.NET/Source/facades/System.Reactive.WindowsRuntime/System.Reactive.WindowsRuntime.csproj +++ b/Rx.NET/Source/facades/System.Reactive.WindowsRuntime/System.Reactive.WindowsRuntime.csproj @@ -4,6 +4,15 @@ uap10.0.18362 + + Legacy facade for Reactive Extensions (Rx) for .NET + readme.md + + + + + + diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/Microsoft.Reactive.Testing.csproj b/Rx.NET/Source/src/Microsoft.Reactive.Testing/Microsoft.Reactive.Testing.csproj index 9b04d2acb7..9621087694 100644 --- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/Microsoft.Reactive.Testing.csproj +++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/Microsoft.Reactive.Testing.csproj @@ -7,6 +7,7 @@ $(DefineConstants);PLATFORM_DOTNET;XUNIT_VISIBILITY_INTERNAL Rx;Reactive;Extensions;Observable;LINQ;Events Reactive Extensions (Rx) for .NET - Testing Library + readme.md $(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 @@ -22,6 +23,8 @@ + + diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/build/NuGet.Readme.md b/Rx.NET/Source/src/Microsoft.Reactive.Testing/build/NuGet.Readme.md new file mode 100644 index 0000000000..554e3ecdaa --- /dev/null +++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/build/NuGet.Readme.md @@ -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. \ No newline at end of file diff --git a/Rx.NET/Source/src/System.Reactive.Observable.Aliases/System.Reactive.Observable.Aliases.csproj b/Rx.NET/Source/src/System.Reactive.Observable.Aliases/System.Reactive.Observable.Aliases.csproj index e88c136270..827da992a5 100644 --- a/Rx.NET/Source/src/System.Reactive.Observable.Aliases/System.Reactive.Observable.Aliases.csproj +++ b/Rx.NET/Source/src/System.Reactive.Observable.Aliases/System.Reactive.Observable.Aliases.csproj @@ -5,6 +5,7 @@ false Rx;Reactive;Extensions;Observable;LINQ;Events Reactive Extensions (Rx) provides the aliases Map, FlatMap, and Filter + readme.md @@ -12,4 +13,8 @@ + + + + \ No newline at end of file diff --git a/Rx.NET/Source/src/System.Reactive.Observable.Aliases/build/NuGet.Readme.md b/Rx.NET/Source/src/System.Reactive.Observable.Aliases/build/NuGet.Readme.md new file mode 100644 index 0000000000..addb71a411 --- /dev/null +++ b/Rx.NET/Source/src/System.Reactive.Observable.Aliases/build/NuGet.Readme.md @@ -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`) \ No newline at end of file diff --git a/Rx.NET/Source/src/System.Reactive/System.Reactive.csproj b/Rx.NET/Source/src/System.Reactive/System.Reactive.csproj index bf9cad48d0..f03416d013 100644 --- a/Rx.NET/Source/src/System.Reactive/System.Reactive.csproj +++ b/Rx.NET/Source/src/System.Reactive/System.Reactive.csproj @@ -4,6 +4,7 @@ false Rx;Reactive;Extensions;Observable;LINQ;Events Reactive Extensions (Rx) for .NET + readme.md @@ -149,6 +150,7 @@ + diff --git a/Rx.NET/Source/src/System.Reactive/build/NuGet.Readme.md b/Rx.NET/Source/src/System.Reactive/build/NuGet.Readme.md new file mode 100644 index 0000000000..de1df0e1a2 --- /dev/null +++ b/Rx.NET/Source/src/System.Reactive/build/NuGet.Readme.md @@ -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 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` + +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 changeEvents = Observable + .FromEventPattern( + 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> Quiescent( + this IObservable src, + TimeSpan minimumInactivityPeriod, + IScheduler scheduler) + { + IObservable onoffs = + from _ in src + from delta in Observable.Return(1, scheduler).Concat(Observable.Return(-1, scheduler).Delay(minimumInactivityPeriod, scheduler)) + select delta; + IObservable outstanding = onoffs.Scan(0, (total, delta) => total + delta); + IObservable 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> 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 \ No newline at end of file