Skip to content

Commit 4feeb5f

Browse files
author
Kaushik Gopal
committed
feat: add button 3 example where you start immediately and then go on with intervals
1 parent e1e6773 commit 4feeb5f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

app/src/main/java/com/morihacky/android/rxjava/TimingDemoFragment.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ public void onNext(Long number) {
106106
});
107107
}
108108

109+
@OnClick(R.id.btn_demo_timing_3)
110+
public void Btn3_RunTask_IntervalOf1s_StartImmediately() {
111+
if (_subscription2 != null && !_subscription2.isUnsubscribed()) {
112+
_subscription2.unsubscribe();
113+
_log(String.format("C3 [%s] XXX BTN KILLED", _getCurrentTimestamp()));
114+
return;
115+
}
116+
117+
_log(String.format("C3 [%s] --- BTN click", _getCurrentTimestamp()));
118+
119+
_subscription2 = Observable//
120+
.timer(0, 1, TimeUnit.SECONDS)//
121+
.subscribe(new Observer<Long>() {
122+
@Override
123+
public void onCompleted() {
124+
_log(String.format("C3 [%s] XXXX COMPLETE", _getCurrentTimestamp()));
125+
}
126+
127+
@Override
128+
public void onError(Throwable e) {
129+
Timber.e(e, "something went wrong in TimingDemoFragment example");
130+
}
131+
132+
@Override
133+
public void onNext(Long number) {
134+
_log(String.format("C3 [%s] NEXT", _getCurrentTimestamp()));
135+
}
136+
});
137+
}
138+
109139
@OnClick(R.id.btn_demo_timing_4)
110140
public void Btn4_RunTask5Times_IntervalOf3s() {
111141
_log(String.format("D4 [%s] --- BTN click", _getCurrentTimestamp()));

0 commit comments

Comments
 (0)