Answered How to fire OnCompleted for Rx stream FromEvent

  • Tuesday, June 19, 2012 2:18 PM
     
     

    Hi,

    I have an Observable stream created using the Observable.FromEvent pattern since my event is of a non standard type.

    At some point during the lifecycle of events I will be notified that no more events will be produced. I wanted to send the OnCompleted rx event to notifiy subscribers that this is the end but I don't see how I can do this using the FromEvent pattern.

    Am I missing something or is this expected for the FromEvent Pattern?

    Thanks

All Replies

  • Tuesday, June 19, 2012 2:55 PM
     
     Answered Has Code

    This is expected from the FromEvent pattern. This is one of the features that Rx has that normal events dont. Normal events do not have the concept of completing. It sounds like you do have a mechanism for knowing when the observable sequence should signal completion. Is this another event? If so, you can combine the sequences with the TakeUntil operator.

    var dataSequence = Observable.FromEventPattern(
    	h => something.SomeEvent += h,
    	h => something.SomeEvent -= h);
    var completionSequence = Observable.FromEventPattern(
    	h => something.SomeOtherEvent += h,
    	h => something.SomeOtherEvent -= h);
    	
    dataSequence
    	.TakeUntil(completionSequence)
    	.Subscribe(......

    Is this what you are looking for?


    Lee Campbell http://LeeCampbell.blogspot.com

    • Marked As Answer by TomacN Tuesday, June 19, 2012 3:44 PM
    •  
  • Tuesday, June 19, 2012 3:44 PM
     
     

    Great answer Lee. So obvious yet so far from my mind!

    Thanks