| 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 DelaySubscription<TSource> : Producer<TSource> |
| 10 |
{ |
| 11 |
private readonly IObservable<TSource> _source; |
| 12 |
private readonly DateTimeOffset? _dueTimeA; |
| 13 |
private readonly TimeSpan? _dueTimeR; |
| 14 |
private readonly IScheduler _scheduler; |
| 15 |
|
| 16 |
public DelaySubscription(IObservable<TSource> source, DateTimeOffset dueTime, IScheduler scheduler) |
| 17 |
{ |
| 18 |
_source = source; |
| 19 |
_dueTimeA = dueTime; |
| 20 |
_scheduler = scheduler; |
| 21 |
} |
| 22 |
|
| 23 |
public DelaySubscription(IObservable<TSource> source, TimeSpan dueTime, IScheduler scheduler) |
| 24 |
{ |
| 25 |
_source = source; |
| 26 |
_dueTimeR = dueTime; |
| 27 |
_scheduler = scheduler; |
| 28 |
} |
| 29 |
|
| 30 |
protected override IDisposable Run(IObserver<TSource> observer, IDisposable cancel, Action<IDisposable> setSink) |
| 31 |
{ |
| 32 |
var sink = new _(observer, cancel); |
| 33 |
setSink(sink); |
| 34 |
|
| 35 |
if (_dueTimeA.HasValue) |
| 36 |
{ |
| 37 |
return _scheduler.Schedule(sink, _dueTimeA.Value, Subscribe); |
| 38 |
} |
| 39 |
else |
| 40 |
{ |
| 41 |
return _scheduler.Schedule(sink, _dueTimeR.Value, Subscribe); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
private IDisposable Subscribe(IScheduler _, _ sink) |
| 46 |
{ |
| 47 |
return _source.SubscribeSafe(sink); |
| 48 |
} |
| 49 |
|
| 50 |
class _ : Sink<TSource>, IObserver<TSource> |
| 51 |
{ |
| 52 |
public _(IObserver<TSource> observer, IDisposable cancel) |
| 53 |
: base(observer, cancel) |
| 54 |
{ |
| 55 |
} |
| 56 |
|
| 57 |
public void OnNext(TSource value) |
| 58 |
{ |
| 59 |
base._observer.OnNext(value); |
| 60 |
} |
| 61 |
|
| 62 |
public void OnError(Exception error) |
| 63 |
{ |
| 64 |
base._observer.OnError(error); |
| 65 |
base.Dispose(); |
| 66 |
} |
| 67 |
|
| 68 |
public void OnCompleted() |
| 69 |
{ |
| 70 |
base._observer.OnCompleted(); |
| 71 |
base.Dispose(); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
#endif |