• An observer subscribes to an Observable. • That observer reacts to whatever item or sequence of items the Observable emits. • It does not block while waiting for the Observable to emit items.
be raised 5 seconds after subscribed val errorObs = Observable }.error<Exception>(Exception("Error!")) }.delay(5,}TimeUnit.SECONDS)} And let’s create a couple of Observables that emit every 1 and 2 seconds val source1 = Observable }.interval(1,}TimeUnit.SECONDS)} }.map}{} }"A"} }}} }.take(10)} val source2}=}Observable }.interval(2,}TimeUnit.SECONDS)} }.map {} }"B"} }}} }.take(5)}
}.interval(1,}TimeUnit.SECONDS)} }.map}{} }"A"} }}} }.take(10)} val source2}=}Observable }.interval(2,}TimeUnit.SECONDS)} }.map {} }"B"} }}} }.take(5)} Observable }.mergeDelayError(source1,}source2,}errorObs)} }.observeOn(AndroidSchedulers.mainThread(), true)} }.subscribe({} }//}Good} }},}{ }//}Bad} }})} 24 MERGE DELAY ERROR OUTPUT 0 1 2 3 4 5 6 7 8 9 10 E L A P S E D S E C O N D S
}.interval(1,}TimeUnit.SECONDS)} }.map}{} }"A"} }}} }.take(10)} val source2}=}Observable }.interval(2,}TimeUnit.SECONDS)} }.map {} }"B"} }}} }.take(5)} Observable }.mergeDelayError(source1,}source2,}errorObs)} }.observeOn(AndroidSchedulers.mainThread(), true)} }.subscribe({} }//}Good} }},}{ }//}Bad} }})} 24 MERGE DELAY ERROR OUTPUT A B A A B A A 0 1 2 3 4 5 6 7 8 9 10 E L A P S E D S E C O N D S A B A B A A A B
}.interval(1,}TimeUnit.SECONDS)} }.map}{} }"A"} }}} }.take(10)} val source2}=}Observable }.interval(2,}TimeUnit.SECONDS)} }.map {} }"B"} }}} }.take(5)} Observable }.mergeDelayError(source1,}source2,}errorObs)} }.observeOn(AndroidSchedulers.mainThread(), true)} }.subscribe({} }//}Good} }},}{ }//}Bad} }})} 25 MERGE DELAY ERROR OUTPUT A B A A B A A 0 1 2 3 4 5 6 7 8 9 10 E L A P S E D S E C O N D S A B A B A A A B
}.interval(1,}TimeUnit.SECONDS)} }.map}{} }"A"} }}} }.take(10)} val source2}=}Observable }.interval(2,}TimeUnit.SECONDS)} }.map {} }"B"} }}} }.take(5)} Observable }.mergeDelayError(source1,}source2,}errorObs)} }.observeOn(AndroidSchedulers.mainThread(), true)} }.subscribe({} }//}Good} }},}{ }//}Bad} }})} 25 MERGE DELAY ERROR OUTPUT A B A A B A A 0 1 2 3 4 5 6 7 8 9 10 E L A P S E D S E C O N D S A B A B A A A B • Error didn’t stop execution
}.interval(1,}TimeUnit.SECONDS)} }.map}{} }"A"} }}} }.take(10)} val source2}=}Observable }.interval(2,}TimeUnit.SECONDS)} }.map {} }"B"} }}} }.take(5)} Observable }.mergeDelayError(source1,}source2,}errorObs)} }.observeOn(AndroidSchedulers.mainThread(), true)} }.subscribe({} }//}Good} }},}{ }//}Bad} }})} 25 MERGE DELAY ERROR OUTPUT A B A A B A A 0 1 2 3 4 5 6 7 8 9 10 E L A P S E D S E C O N D S A B A B A A A B • Error didn’t stop execution • After source1 and source2 complete, an error will be emitted here
• Combines the most recently emitted items through the function provided • Also smart, will “give up” when will know for sure that can’t combine further emissions 34 1 x 1