Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make ScheduledSubject more flexible.

  • Loading branch information...
commit dc29cfcae0f962fcb56a0ae3851b943ade5a792b 1 parent 353ae7d
@jlaanstra jlaanstra authored
Showing with 9 additions and 4 deletions.
  1. +9 −4 ReactiveUI/ScheduledSubject.cs
View
13 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()
Please sign in to comment.
Something went wrong with that request. Please try again.