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;








0















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










share|improve this question




























    0















    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










    share|improve this question
























      0












      0








      0


      1






      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










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 8:28









      nicolas asinovichnicolas asinovich

      6621018




      6621018






















          2 Answers
          2






          active

          oldest

          votes


















          1














          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).






          share|improve this answer

























          • 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


















          1














          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)






          share|improve this answer























          • 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











          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
          );



          );













          draft saved

          draft discarded


















          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









          1














          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).






          share|improve this answer

























          • 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















          1














          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).






          share|improve this answer

























          • 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













          1












          1








          1







          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).






          share|improve this answer















          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).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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 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

















          • 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
















          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













          1














          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)






          share|improve this answer























          • 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















          1














          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)






          share|improve this answer























          • 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













          1












          1








          1







          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)






          share|improve this answer













          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)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 8:45









          FernandomsFernandoms

          327112




          327112












          • 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
















          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

















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript