Proposed Answer Combining Sequences

  • Friday, August 03, 2012 2:48 PM
     
     

    Hi,

    I have the following scenario and I'm wondering if Rx is a good fit to solve this or indeed if it just over complicates things. At the moment I'm thinking the latter but then I might be missing something. The reason I'm swaying away from Rx is because i'm not expecting multiple calls to OnNext. Generally this feels more like a Task T scenario. That said the ability to combine multiple streams is appealing.

    I have a class that does the following all running on the UI thread:-

    1. Subscribes to a Loaded event

    2. Overrides a virtual method call that passes some data

    e.g. override void SomeState(string state) { }

    I need to do 2 things:

    1. Parse the state string and create a new string. I want to do this on a thread pool thread because it might take some time and I don't want to block the UI.

    2. Use that new string from above and execute another action. However I only want to execute that action if the Loaded event has fired. Conversely if the Loaded event fires and I have not finished parsing the string then I want to wait until that is completed or be notified on the UI thread when it has happened so I can go ahead and execute this other action.

    My non rx solution is to use some state to decide if the LoadedEvent has fired and similar to see if the state has been parsed. In the middle is a Task<T> which does the parsing.

    My current rx solution involves turning the parsed state into an Observable and the LoadedEvent and then using CombineLatest to trigger the final action.

    Any thoughts?

    I'm hoping what I am describing is a reasonably common requirement. Don't do something unless 2 things have happened and one of those things kicks off an async but of processing.

    Thanks

All Replies

  • Friday, August 03, 2012 8:33 PM
     
     Proposed Answer

    Hi,

    > I'm wondering if Rx is a good fit to solve this or indeed if it just over complicates things [snip]

    Do you feel that your Rx solution is over complicated compared to your non-Rx solution?

    CombineLatest seems like a good approach to me.  (Though perhaps Zip is more semantically accurate in your case.)

    - Dave


    http://davesexton.com/blog

    • Proposed As Answer by LeeCampbell Tuesday, August 14, 2012 10:21 AM
    •