io.reactivex.schedulers.Timed Java Examples
The following examples show how to use
io.reactivex.schedulers.Timed.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataCleaner.java From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 | 5 votes |
/** * Clear application data. * * @param clearFavorites true to clear favorite movies, otherwise or not. * @return RxJava Observable for the timed stages. */ public Observable<Timed<Stage>> clearData(final boolean clearFavorites) { final ObservableOnSubscribe<Stage> clearingTasks = (ObservableEmitter<Stage> emitter) -> { if (clearFavorites) { // Clear favorites emitter.onNext(Stage.FAVORITES); favoriteMovieCollection.clear(); favoriteStore.clearData(); } // Clear HTTP cache emitter.onNext(Stage.HTTP_CACHE); movieDbService.clearCache(); // Clear image cache emitter.onNext(Stage.IMAGE_CACHE); glide.clearDiskCache(); emitter.onNext(Stage.COMPLETE); // Emit an extra event to delay the onComplete event. emitter.onComplete(); }; return Observable.create(clearingTasks) .timeInterval() .map(delayTimeCalculator) .scan(delayAggregation) .delay(item -> Observable.timer(item.time(), TimeUnit.MILLISECONDS)) .subscribeOn(Schedulers.io()); }
Example #2
Source File: ExampleUnitTest.java From RxAndroid-Sample with Apache License 2.0 | 5 votes |
@Test public void testTimestampObservable() throws InterruptedException { Observable.interval(100, TimeUnit.MILLISECONDS) .take(3) .timestamp() .subscribe(new Observer<Timed<Long>>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(Timed<Long> longTimed) { System.out.println(longTimed); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); Thread.sleep(3000); }
Example #3
Source File: RxComboDetector.java From RxComboDetector with MIT License | 5 votes |
@VisibleForTesting static Flowable<Integer> detect(Flowable<Integer> clicks, final long maxIntervalMillis, final int minComboTimesCared) { return clicks.timestamp() .scan((lastOne, thisOne) -> { if (thisOne.time() - lastOne.time() <= maxIntervalMillis) { return new Timed<>(lastOne.value() + 1, thisOne.time(), thisOne.unit()); } else { return new Timed<>(1, thisOne.time(), thisOne.unit()); } }) .map(Timed::value) .filter(combo -> combo >= minComboTimesCared); }
Example #4
Source File: ExampleUnitTest.java From RxAndroid-Sample with Apache License 2.0 | 4 votes |
@Test public void testTimeIntervalObservable() throws InterruptedException { Observable.interval(100, TimeUnit.MILLISECONDS) .take(3) .timeInterval() .subscribe(new Subject<Timed<Long>>() { @Override public boolean hasObservers() { return false; } @Override public boolean hasThrowable() { return false; } @Override public boolean hasComplete() { return false; } @Override public Throwable getThrowable() { return null; } @Override protected void subscribeActual(Observer<? super Timed<Long>> observer) { } @Override public void onSubscribe(Disposable d) { } @Override public void onNext(Timed<Long> longTimed) { System.out.println("onNext: " + longTimed); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); Thread.sleep(3000); }