February 2020
Intermediate to advanced
412 pages
9h 36m
English
The timestamp() operator attaches a timestamp to every item emitted by an Observable, as shown in the following code:
import io.reactivex.rxjava3.core.Observable;import java.util.concurrent.TimeUnit;public class Ch3_67 { public static void main(String[] args) { Observable.just("One", "Two", "Three") .timestamp(TimeUnit.SECONDS) .subscribe(i -> System.out.println("Received: " + i)); }}
The output is as follows:
Received: Timed[time=1561694750, unit=SECONDS, value=One]Received: Timed[time=1561694750, unit=SECONDS, value=Two]Received: Timed[time=1561694750, unit=SECONDS, value=Three]
As you can see, the results are wrapped inside the object of the Timed class, which provide accessors to the values that we can unwrap as follows: ...
Read now
Unlock full access