RxJava - delay

2020. 12. 9. 15:58 안드로이드/개발 TIP

RxJava Delay



Observable<String> myObservable = Observable.create(
new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
subscriber.onNext(
"text1");
subscriber.onNext("text2");
subscriber.onCompleted();
}
}
).delay(
2, TimeUnit.SECONDS, Schedulers.trampoline());
myObservable.subscribe(subScriber);



private Subscriber<String> subScriber = new Subscriber<String>() {
@Override
public void onCompleted() {
        Log.e("complete", "complete");

}

@Override
public void onError(Throwable e) {
Log.e("err", e.getMessage());
}

@Override
public void onNext(String s) {
Log.e("res", s);
}
};



result


06-25 02:40:43.655 12316-12316/com.akaisun.school E/time: 02:43
06-25 02:40:43.655 12316-12316/com.akaisun.school E/s: text1
06-25 02:40:45.655 12316-12316/com.akaisun.school E/time: 02:45
06-25 02:40:45.655 12316-12316/com.akaisun.school E/s: text2
06-25 02:40:47.655 12316-12316/com.akaisun.school E/complete: complete



출처: https://akaisun.tistory.com/28?category=622886 [아카이의 개발창고]