forked from idg10/prog-cs-8-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
38 lines (33 loc) · 1.04 KB
/
Program.cs
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
30
31
32
33
34
35
36
37
38
using System;
using System.Reactive.Linq;
using System.Reactive.Subjects;
namespace DelegateBasedPubSub
{
class Program
{
static void Main()
{
SubscribeWihoutImplementingIObserver();
}
public static void DelegateBasedHotSource()
{
IObservable<char> singularHotSource = Observable.Create(
(Func<IObserver<char>, IDisposable>)(obs =>
{
while (true)
{
obs.OnNext(Console.ReadKey(true).KeyChar);
}
}));
IConnectableObservable<char> keySource = singularHotSource.Publish();
keySource.Subscribe(new MySubscriber<char>());
keySource.Subscribe(new MySubscriber<char>());
}
public static void SubscribeWihoutImplementingIObserver()
{
var source = new KeyWatcher();
source.Subscribe(value => Console.WriteLine("Received: " + value));
source.Run();
}
}
}