I have a dynamic list of commands which shall be executed. Some of these command objects should be executed in a background thread and some of them have to be executed on the UiThread as they change views and trigger animations.
Some commands are not allowed to be executed before another command has been finished. E.g. C1 triggers a fade in animation which lasts 2 sec. C2 triggers a fade out animation. => The delay between the commands is dynamic.
I'm a newbie to RXJava. My solution works but seems not to be very elegant.
=> Before I convert the list of commands into an Observable I add "Wait" commands where needed. The wait command just calls Thread.sleep(delayInMs). Observation and subscription both run on the same background thread. The Observable emits the commands. If the command is an instance of UiCommand the subscriber posts the execution to the uiThread otherwise it executes the command on the background thread.
What is the best way to solve this problem with RXJava? I would like to get rid of the UiThread posts and the upfront preparation of the list. But replace this with RXJava features.
Here seems like you can use transformers to convert your observable from synchronous to asynchronous.
Take a look of these examples