Permalink
Browse files

Make ScheduledSubject more flexible.

  • Loading branch information...
1 parent 353ae7d commit dc29cfcae0f962fcb56a0ae3851b943ade5a792b @jlaanstra jlaanstra committed Feb 1, 2013
Showing with 9 additions and 4 deletions.
  1. +9 −4 ReactiveUI/ScheduledSubject.cs
@@ -9,26 +9,31 @@ namespace ReactiveUI
{
public class ScheduledSubject<T> : ISubject<T>
{
- public ScheduledSubject(IScheduler scheduler, IObserver<T> defaultObserver = null)
+ public ScheduledSubject(IScheduler scheduler, IObserver<T> defaultObserver = null, ISubject<T> defaultSubject = null)
{
_scheduler = scheduler;
_defaultObserver = defaultObserver;
+ _subject = defaultSubject ?? new Subject<T>();
- if (defaultObserver != null) {
+ if (defaultObserver != null)
+ {
_defaultObserverSub = _subject.ObserveOn(_scheduler).Subscribe(_defaultObserver);
}
}
readonly IObserver<T> _defaultObserver;
readonly IScheduler _scheduler;
- readonly Subject<T> _subject = new Subject<T>();
+ readonly ISubject<T> _subject;
int _observerRefCount = 0;
IDisposable _defaultObserverSub;
public void Dispose()
{
- _subject.Dispose();
+ if (_subject is IDisposable)
+ {
+ ((IDisposable)_subject).Dispose();
+ }
}
public void OnCompleted()

0 comments on commit dc29cfc

Please sign in to comment.