-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathObservableRange.linq
45 lines (33 loc) · 1.15 KB
/
ObservableRange.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<Query Kind="Statements">
<NuGetReference>System.Interactive</NuGetReference>
<NuGetReference>System.Reactive</NuGetReference>
<Namespace>System.Collections.ObjectModel</Namespace>
<Namespace>System.Reactive.Concurrency</Namespace>
<Namespace>System.Reactive.Linq</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>
var sw = new Stopwatch();
sw.Start();
var query = Observable.Range(1, 10)
.Where(num => num % 2 == 0)
.ObserveOn(TaskPoolScheduler.Default)
.Do(num => Task.Delay((10 - num) * 200).Wait());
query.Subscribe(num => Console.WriteLine(num),
() => Console.WriteLine("Elapsed Time: " + sw.ElapsedTicks)
);
Console.WriteLine("Done. You can continue working.");
//var query = Observable.Range(1,10)
// .Where(num => num % 2 == 0)
// .Do(num => Task.Delay((10 - num) * 200).Wait());
//
//query.Subscribe(val => Console.WriteLine(val));
//var query = Observable.Range(1, 10)
// .ObserveOn(TaskPoolScheduler.Default)
// .Where(num => num % 2 == 0)
// .Do(num => Task.Delay((10 - num) * 200).Wait())
// .Subscribe(num => Console.WriteLine(num),
// () =>
// {
// Console.WriteLine("Elapsed Time: " + sw.ElapsedTicks);
// }
// );