June 2018
Intermediate to advanced
310 pages
6h 32m
English
This is a strange subject since, unlike the others, it doesn't update its subscribers. So, what is it good for?
What if you wanted to have a very basic functionality, simply updating a screen with the latest value and never refreshing it again until the screen is closed:
val subject = AsyncSubject.create<Int>()
Here is the output:
S1 subscribesS1 subscribedS2 subscribesS2 subscribedS1 23 <= This is the final valueS2 23
Be careful, though. Since AsyncSubject waits for the sequence to complete, if the sequence is infinite, it will never call its subscribers:
// Infinite sequence of 1val o = Observable.generate<Int> { 1 }.publish()...o.connect() // Hangs here forever
Read now
Unlock full access