Last active
October 10, 2016 19:43
-
-
Save herecydev/6c61cbf1f0602715413a63c5ab54fbd3 to your computer and use it in GitHub Desktop.
Merge problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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