GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: use for a simpler solution to the polling problem (thanks @mand… · java4ever/RxJava-Android-Samples@588df66

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/src/main/java/com/morihacky/android/rxjava/fragments
    • PollingFragment.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/src/main/java/com/morihacky/android/rxjava/fragments/PollingFragment.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/fragments/PollingFragment.java
+23-23Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import rx.Subscription;
2828
import rx.functions.Action0;
2929
import rx.functions.Action1;
30+
import rx.functions.Func1;
3031
import rx.schedulers.Schedulers;
3132
import rx.subscriptions.CompositeSubscription;
3233
import timber.log.Timber;
@@ -35,7 +36,7 @@ public class PollingFragment
3536
extends BaseFragment {
3637

3738
public static final int INITIAL_DELAY = 0;
38-
public static final int POLLING_INTERVAL = 1000;
39+
public static final int POLLING_INTERVAL = 500;
3940
@Bind(R.id.list_threading_log) ListView _logsList;
4041

4142
private LogAdapter _adapter;
@@ -72,28 +73,27 @@ public void onDestroy() {
7273
@OnClick(R.id.btn_start_simple_polling)
7374
public void onStartSimplePollingClicked() {
7475
_setupLogger();
75-
_log(String.format("Simple String polling - %s", _counter));
76-
_subscriptions.add(Observable.create(
77-
new Observable.OnSubscribe<String>() {
78-
@Override
79-
public void call(final Subscriber<? super String> subscriber) {
80-
Subscription subscription = _worker
81-
.schedulePeriodically(new Action0() {
82-
@Override
83-
public void call() {
84-
subscriber.onNext(_doNetworkCallAndGetStringResult());
85-
}
86-
}, INITIAL_DELAY, POLLING_INTERVAL, TimeUnit.MILLISECONDS);
87-
subscriber.add(subscription);
88-
}
89-
})
90-
.take(10)
91-
.subscribe(new Action1<String>() {
92-
@Override
93-
public void call(String s) {
94-
_log(String.format("String polling - %s", s));
95-
}
96-
})
76+
77+
_subscriptions.add(//
78+
Observable.interval(INITIAL_DELAY, POLLING_INTERVAL, TimeUnit.MILLISECONDS)
79+
.map(new Func1<Long, String>() {
80+
@Override
81+
public String call(Long heartBeat) {
82+
return _doNetworkCallAndGetStringResult();
83+
}
84+
}).take(5)
85+
.doOnSubscribe(new Action0() {
86+
@Override
87+
public void call() {
88+
_log(String.format("Simple String polling - %s", _counter));
89+
}
90+
})
91+
.subscribe(new Action1<String>() {
92+
@Override
93+
public void call(String s) {
94+
_log(String.format("Start simple polling - %s", s));
95+
}
96+
})
9797
);
9898
}
9999

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.