본문 바로가기
안드로이드

RxJava - delay

by 아카이sun 2016. 6. 25.


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


댓글