What best practice to call requests if no connection - repeat call every 4-5 seconds until we get response, use Rx Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?What are the best practices for SQLite on Android?What is the best practice to make http calls in androidVerify that method is called in onNext of RxJava SubscriberSchedulers.io() not returning to main threadRxJava subscribeOn and observeOn not override the original Scheduler set before?Rxjava observeOn and subscribeOn in RetrofitAndroid RxJava Observable blocking uiWhy use subscribeOn in every Observable method in RxJavaRxAndroid operator retryWhen is invoked but does not resubscribeObservable do not call onComplete (sqlbrite - mapToOneOrDefault)
Java 8 stream max() function argument type Comparator vs Comparable
Antler Helmet: Can it work?
Can a non-EU citizen traveling with me come with me through the EU passport line?
Is there a documented rationale why the House Ways and Means chairman can demand tax info?
Do I really need recursive chmod to restrict access to a folder?
Is there a "higher Segal conjecture"?
The logistics of corpse disposal
What does the "x" in "x86" represent?
How discoverable are IPv6 addresses and AAAA names by potential attackers?
Diagram with tikz
If Jon Snow became King of the Seven Kingdoms what would his regnal number be?
How to find all the available tools in macOS terminal?
Check which numbers satisfy the condition [A*B*C = A! + B! + C!]
How can I make names more distinctive without making them longer?
How to motivate offshore teams and trust them to deliver?
G-Code for resetting to 100% speed
How does a Death Domain cleric's Touch of Death feature work with Touch-range spells delivered by familiars?
How to deal with a team lead who never gives me credit?
Why is "Consequences inflicted." not a sentence?
Why is "Captain Marvel" translated as male in Portugal?
What is this single-engine low-wing propeller plane?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
If a contract sometimes uses the wrong name, is it still valid?
Is the address of a local variable a constexpr?
What best practice to call requests if no connection - repeat call every 4-5 seconds until we get response, use Rx
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?What are the best practices for SQLite on Android?What is the best practice to make http calls in androidVerify that method is called in onNext of RxJava SubscriberSchedulers.io() not returning to main threadRxJava subscribeOn and observeOn not override the original Scheduler set before?Rxjava observeOn and subscribeOn in RetrofitAndroid RxJava Observable blocking uiWhy use subscribeOn in every Observable method in RxJavaRxAndroid operator retryWhen is invoked but does not resubscribeObservable do not call onComplete (sqlbrite - mapToOneOrDefault)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
For example we have some methods
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
what best and easiest way for make use RX if no connextion repeat call every 4-5 seconds until we get response
android kotlin system.reactive rx-java2
add a comment |
For example we have some methods
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
what best and easiest way for make use RX if no connextion repeat call every 4-5 seconds until we get response
android kotlin system.reactive rx-java2
add a comment |
For example we have some methods
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
what best and easiest way for make use RX if no connextion repeat call every 4-5 seconds until we get response
android kotlin system.reactive rx-java2
For example we have some methods
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
what best and easiest way for make use RX if no connextion repeat call every 4-5 seconds until we get response
android kotlin system.reactive rx-java2
android kotlin system.reactive rx-java2
asked Mar 22 at 8:28
nicolas asinovichnicolas asinovich
6621018
6621018
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
you can use retryWhen
.
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.retryWhen error ->
error.flatMap Observable.timer(4, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
And if you want to check the error is caused exactly by no connection, you can do it in error.flatMap
block like if(it is NoConnectionException)
.
I imagine it's the same on Java as C# so you should always move yoursubscribeOn
andobserveOn
to as late in the pipeline as possible.
– Enigmativity
Mar 22 at 21:58
@Enigmativity thanks for comment. I've fixed my answer forobserveOn
being in afterretryWhen
– Choim
Mar 25 at 5:00
add a comment |
For this purpose you could use this
source.retryWhen(errors -> errors.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS)))
the retryWhen
code will run if you get and error, until you receive an onSuccess
in your code, it would be something like:
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retryWhen(e -> e.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS))
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
I imagine it's the same on Java as C# so you should always move yoursubscribeOn
andobserveOn
to as late in the pipeline as possible.
– Enigmativity
Mar 22 at 21:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55295591%2fwhat-best-practice-to-call-requests-if-no-connection-repeat-call-every-4-5-sec%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
you can use retryWhen
.
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.retryWhen error ->
error.flatMap Observable.timer(4, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
And if you want to check the error is caused exactly by no connection, you can do it in error.flatMap
block like if(it is NoConnectionException)
.
I imagine it's the same on Java as C# so you should always move yoursubscribeOn
andobserveOn
to as late in the pipeline as possible.
– Enigmativity
Mar 22 at 21:58
@Enigmativity thanks for comment. I've fixed my answer forobserveOn
being in afterretryWhen
– Choim
Mar 25 at 5:00
add a comment |
you can use retryWhen
.
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.retryWhen error ->
error.flatMap Observable.timer(4, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
And if you want to check the error is caused exactly by no connection, you can do it in error.flatMap
block like if(it is NoConnectionException)
.
I imagine it's the same on Java as C# so you should always move yoursubscribeOn
andobserveOn
to as late in the pipeline as possible.
– Enigmativity
Mar 22 at 21:58
@Enigmativity thanks for comment. I've fixed my answer forobserveOn
being in afterretryWhen
– Choim
Mar 25 at 5:00
add a comment |
you can use retryWhen
.
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.retryWhen error ->
error.flatMap Observable.timer(4, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
And if you want to check the error is caused exactly by no connection, you can do it in error.flatMap
block like if(it is NoConnectionException)
.
you can use retryWhen
.
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.retryWhen error ->
error.flatMap Observable.timer(4, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
And if you want to check the error is caused exactly by no connection, you can do it in error.flatMap
block like if(it is NoConnectionException)
.
edited Mar 25 at 4:58
answered Mar 22 at 8:51
ChoimChoim
1416
1416
I imagine it's the same on Java as C# so you should always move yoursubscribeOn
andobserveOn
to as late in the pipeline as possible.
– Enigmativity
Mar 22 at 21:58
@Enigmativity thanks for comment. I've fixed my answer forobserveOn
being in afterretryWhen
– Choim
Mar 25 at 5:00
add a comment |
I imagine it's the same on Java as C# so you should always move yoursubscribeOn
andobserveOn
to as late in the pipeline as possible.
– Enigmativity
Mar 22 at 21:58
@Enigmativity thanks for comment. I've fixed my answer forobserveOn
being in afterretryWhen
– Choim
Mar 25 at 5:00
I imagine it's the same on Java as C# so you should always move your
subscribeOn
and observeOn
to as late in the pipeline as possible.– Enigmativity
Mar 22 at 21:58
I imagine it's the same on Java as C# so you should always move your
subscribeOn
and observeOn
to as late in the pipeline as possible.– Enigmativity
Mar 22 at 21:58
@Enigmativity thanks for comment. I've fixed my answer for
observeOn
being in after retryWhen
– Choim
Mar 25 at 5:00
@Enigmativity thanks for comment. I've fixed my answer for
observeOn
being in after retryWhen
– Choim
Mar 25 at 5:00
add a comment |
For this purpose you could use this
source.retryWhen(errors -> errors.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS)))
the retryWhen
code will run if you get and error, until you receive an onSuccess
in your code, it would be something like:
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retryWhen(e -> e.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS))
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
I imagine it's the same on Java as C# so you should always move yoursubscribeOn
andobserveOn
to as late in the pipeline as possible.
– Enigmativity
Mar 22 at 21:58
add a comment |
For this purpose you could use this
source.retryWhen(errors -> errors.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS)))
the retryWhen
code will run if you get and error, until you receive an onSuccess
in your code, it would be something like:
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retryWhen(e -> e.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS))
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
I imagine it's the same on Java as C# so you should always move yoursubscribeOn
andobserveOn
to as late in the pipeline as possible.
– Enigmativity
Mar 22 at 21:58
add a comment |
For this purpose you could use this
source.retryWhen(errors -> errors.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS)))
the retryWhen
code will run if you get and error, until you receive an onSuccess
in your code, it would be something like:
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retryWhen(e -> e.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS))
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
For this purpose you could use this
source.retryWhen(errors -> errors.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS)))
the retryWhen
code will run if you get and error, until you receive an onSuccess
in your code, it would be something like:
private fun getMobileData()
apiClient.getMobileData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retryWhen(e -> e.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS))
.subscribe( result ->
datasBehavior.onNext(result.datas)
actionsBehavior.onNext(result.actions)
) it.message .addTo(subscriptions)
answered Mar 22 at 8:45
FernandomsFernandoms
327112
327112
I imagine it's the same on Java as C# so you should always move yoursubscribeOn
andobserveOn
to as late in the pipeline as possible.
– Enigmativity
Mar 22 at 21:58
add a comment |
I imagine it's the same on Java as C# so you should always move yoursubscribeOn
andobserveOn
to as late in the pipeline as possible.
– Enigmativity
Mar 22 at 21:58
I imagine it's the same on Java as C# so you should always move your
subscribeOn
and observeOn
to as late in the pipeline as possible.– Enigmativity
Mar 22 at 21:58
I imagine it's the same on Java as C# so you should always move your
subscribeOn
and observeOn
to as late in the pipeline as possible.– Enigmativity
Mar 22 at 21:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55295591%2fwhat-best-practice-to-call-requests-if-no-connection-repeat-call-every-4-5-sec%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown