-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMulticast 1.linq
29 lines (22 loc) · 1015 Bytes
/
Multicast 1.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<Query Kind="Statements">
<Reference><ApplicationData>\LINQPad\Samples\Programming Reactive Extensions and LINQ\System.Reactive.dll</Reference>
<Namespace>System.Reactive</Namespace>
<Namespace>System.Reactive.Linq</Namespace>
</Query>
/* Multicast 1:
*
* Multicast plays an Observable onto a Subject - this is useful for making Cold
* Observables into Hot Observables. Practically speaking, it's also useful in
* class implementations where you want to return "an Observable that is based
* on this other Observable, but every once in awhile I want to signal it
* by-hand"
*/
// IEnumerable<T>.ToObservable() is a *Cold* Observable - every time you
// subscribe to it, you get a new copy.
var input = new[] {1,2,3}.ToObservable();
var output = input.Multicast(new Subject<int>());
// This doesn't do anything until Connect is called to actually connect the
// input to the Subject.
output.Dump();
Util.ReadLine("Press any key to continue");
output.Connect();