following are the operators which are often useful with observables.
sr.no. | operator & description |
---|---|
1 |
delay register action to handle observable life-cycle events. |
2 |
materialize/dematerialize represents item emitted and notification sent. |
3 |
observeon specify the scheduler to be observed. |
4 |
serialize force observable to make serialized calls. |
5 |
subscribe operate upon the emissions of items and notifications like complete from an observable |
6 |
subscribeon specify the scheduler to be used by an observable when it is subscribed to. |
7 |
timeinterval convert an observable to emit indications of the amount of time elapsed between emissions. |
8 |
timeout issues error notification if specified time occurs without emitting any item. |
9 |
timestamp attach timestamp to each item emitted. |
9 |
using creates a disposable resource or same lifespan as that of observable. |
utility operator example
create the following java program using any editor of your choice in, say, c:\> rxjava.
observabletester.java
import io.reactivex.observable; //using subscribe operator to subscribe to an observable public class observabletester { public static void main(string[] args) { string[] letters = {"a", "b", "c", "d", "e", "f", "g"}; final stringbuilder result = new stringbuilder(); observable<string> observable = observable.fromarray(letters); observable.subscribe( letter -> result.append(letter)); system.out.println(result); } }
verify the result
compile the class using javac compiler as follows −
c:\rxjava>javac observabletester.java
now run the observabletester as follows −
c:\rxjava>java observabletester
it should produce the following output −
abcdefg