Skip to main content
Commonmark migration
Source Link

This is a rather educational, out of curiosity question. Consider the following snippet:

var enumerable = Enumerable.Range(0, 5); var observable = enumerable.ToObservable(); var enu = observable.Concat(observable).ToEnumerable(); enu.ToObservable().SubscribeDebug(); 

Where SubscribeDebug subscribes a simple observer:

public class DebugObserver<T> : IObserver<T> { public void OnCompleted() { Debug.WriteLine("Completed"); } public void OnError(Exception error) { Debug.WriteLine("Error"); } public void OnNext(T value) { Debug.WriteLine("Value: {0}", value); } } 

The output of this is:

Value: 0

 

Value: 1

 

Value: 2

 

Value: 3

 

Value: 4

And then blocks. Can someone help me understand the underlying reason why it happens and why the observable does not complete? I have noticed that it does complete without the Concat call, but blocks with it.

This is a rather educational, out of curiosity question. Consider the following snippet:

var enumerable = Enumerable.Range(0, 5); var observable = enumerable.ToObservable(); var enu = observable.Concat(observable).ToEnumerable(); enu.ToObservable().SubscribeDebug(); 

Where SubscribeDebug subscribes a simple observer:

public class DebugObserver<T> : IObserver<T> { public void OnCompleted() { Debug.WriteLine("Completed"); } public void OnError(Exception error) { Debug.WriteLine("Error"); } public void OnNext(T value) { Debug.WriteLine("Value: {0}", value); } } 

The output of this is:

Value: 0

 

Value: 1

 

Value: 2

 

Value: 3

 

Value: 4

And then blocks. Can someone help me understand the underlying reason why it happens and why the observable does not complete? I have noticed that it does complete without the Concat call, but blocks with it.

This is a rather educational, out of curiosity question. Consider the following snippet:

var enumerable = Enumerable.Range(0, 5); var observable = enumerable.ToObservable(); var enu = observable.Concat(observable).ToEnumerable(); enu.ToObservable().SubscribeDebug(); 

Where SubscribeDebug subscribes a simple observer:

public class DebugObserver<T> : IObserver<T> { public void OnCompleted() { Debug.WriteLine("Completed"); } public void OnError(Exception error) { Debug.WriteLine("Error"); } public void OnNext(T value) { Debug.WriteLine("Value: {0}", value); } } 

The output of this is:

Value: 0

Value: 1

Value: 2

Value: 3

Value: 4

And then blocks. Can someone help me understand the underlying reason why it happens and why the observable does not complete? I have noticed that it does complete without the Concat call, but blocks with it.

Source Link
Martin Zikmund
  • 39.2k
  • 7
  • 74
  • 95

Why does repeated Enumerable to Observable conversion block

This is a rather educational, out of curiosity question. Consider the following snippet:

var enumerable = Enumerable.Range(0, 5); var observable = enumerable.ToObservable(); var enu = observable.Concat(observable).ToEnumerable(); enu.ToObservable().SubscribeDebug(); 

Where SubscribeDebug subscribes a simple observer:

public class DebugObserver<T> : IObserver<T> { public void OnCompleted() { Debug.WriteLine("Completed"); } public void OnError(Exception error) { Debug.WriteLine("Error"); } public void OnNext(T value) { Debug.WriteLine("Value: {0}", value); } } 

The output of this is:

Value: 0

Value: 1

Value: 2

Value: 3

Value: 4

And then blocks. Can someone help me understand the underlying reason why it happens and why the observable does not complete? I have noticed that it does complete without the Concat call, but blocks with it.