Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable/Timestamp.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 #if !NO_PERF
4 using System;
5 using System.Reactive.Concurrency;
6
7 namespace System.Reactive.Linq.ObservableImpl
8 {
9 class Timestamp<TSource> : Producer<Timestamped<TSource>>
10 {
11 private readonly IObservable<TSource> _source;
12 private readonly IScheduler _scheduler;
13
14 public Timestamp(IObservable<TSource> source, IScheduler scheduler)
15 {
16 _source = source;
17 _scheduler = scheduler;
18 }
19
20 protected override IDisposable Run(IObserver<Timestamped<TSource>> observer, IDisposable cancel, Action<IDisposable> setSink)
21 {
22 var sink = new _(this, observer, cancel);
23 setSink(sink);
24 return _source.SubscribeSafe(sink);
25 }
26
27 class _ : Sink<Timestamped<TSource>>, IObserver<TSource>
28 {
29 private readonly Timestamp<TSource> _parent;
30
31 public _(Timestamp<TSource> parent, IObserver<Timestamped<TSource>> observer, IDisposable cancel)
32 : base(observer, cancel)
33 {
34 _parent = parent;
35 }
36
37 public void OnNext(TSource value)
38 {
39 base._observer.OnNext(new Timestamped<TSource>(value, _parent._scheduler.Now));
40 }
41
42 public void OnError(Exception error)
43 {
44 base._observer.OnError(error);
45 base.Dispose();
46 }
47
48 public void OnCompleted()
49 {
50 base._observer.OnCompleted();
51 base.Dispose();
52 }
53 }
54 }
55 }
56 #endif