Skip to content

Instantly share code, notes, and snippets.

@herecydev
Last active October 10, 2016 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herecydev/6c61cbf1f0602715413a63c5ab54fbd3 to your computer and use it in GitHub Desktop.
Save herecydev/6c61cbf1f0602715413a63c5ab54fbd3 to your computer and use it in GitHub Desktop.
Merge problem
//Instatiate A and call start
public class A
{
private readonly C _c;
public A()
{
_c = new C();
var b = new B(new[] { _c });
b.Subscribe(message =>
{
Console.WriteLine(message);
if (message == "throw please!")
throw new Exception();
});
}
public void Start() => _c.Start();
}
public class B : IObservable<string>
{
private readonly IObservable<string> _observable;
public B(IEnumerable<IObservable<string>> observables)
{
_observable = observables.Merge();
}
public IDisposable Subscribe(IObserver<string> observer) => _observable.Subscribe(observer);
}
public class C : IObservable<string>
{
private readonly Subject<string> _subject = new Subject<string>();
public void Start()
{
_subject.OnNext("Hello");
try
{
_subject.OnNext("throw please!");
}
catch(Exception ex)
{
// I'll catch it; I sometimes expect them to throw.
}
_subject.OnNext("World");
}
public IDisposable Subscribe(IObserver<string> observer) => _subject.Subscribe(observer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment