# RxBackoff **Repository Path**: HarmonyOS-tpc/RxBackoff ## Basic Information - **Project Name**: RxBackoff - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-09-17 - **Last Updated**: 2023-04-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## RxBackoff ## Introduction An openharmony library useful when you want a retry operation using Exponential backoff algorithm. ## Usage instructions Set rxjava Observable upon exception or network failure, retry binaryExponentialBackoff. ```java Observable.error(new Exception("sample")) .doOnError(new Consumer() { @Override public void accept(Throwable throwable) throws Exception { // put log here LogUtil.info(TAG, " accept:"+throwable.getLocalizedMessage()); } }) .retryWhen(RxBackoff.of(BackoffExt.binaryExponentialBackoff(), 5).observable()) .subscribeOn(Schedulers.io()) .subscribe(new Consumer() { @Override public void accept(Object object) { LogUtil.info(TAG, "subscribe accept..."); } }, new Consumer() { @Override public void accept(Throwable throwable) { LogUtil.info(TAG, " accept error:"+throwable.getMessage()); throwable.printStackTrace(); } }); ``` Set rxjava Observable upon exception or network failure, retry exponentialBackoff. ```java Observable.error(new Exception("sample")) .doOnError(new Consumer() { @Override public void accept(Throwable throwable) throws Exception { // put log here LogUtil.info(TAG, " accept:"+throwable.getLocalizedMessage()); } }) .retryWhen(RxBackoff.of(BackoffExt.exponentialBackoff(), 5).observable()) .subscribeOn(Schedulers.io()) .subscribe(new Consumer() { @Override public void accept(Object object) { LogUtil.info(TAG, "subscribe accept..."); } }, new Consumer() { @Override public void accept(Throwable throwable) { LogUtil.info(TAG, " accept error:"+throwable.getMessage()); throwable.printStackTrace(); } }); ``` Set rxjava Observable upon exception or network failure, retry randomInterval. ```java Observable.error(new Exception("sample")) .doOnError(new Consumer() { @Override public void accept(Throwable throwable) throws Exception { // put log here LogUtil.info(TAG, " accept:"+throwable.getLocalizedMessage()); } }) .retryWhen(RxBackoff.of(BackoffExt.randomInterval(), 5).observable()) .subscribeOn(Schedulers.io()) .subscribe(new Consumer() { @Override public void accept(Object object) { LogUtil.info(TAG, "subscribe accept..."); } }, new Consumer() { @Override public void accept(Throwable throwable) { LogUtil.info(TAG, " accept error:"+throwable.getMessage()); throwable.printStackTrace(); } }); ``` ## Installation instruction 1 .For using RxBackoff module in sample app,include the below library dependency: Add the dependencies in entry/build.gradle as below : dependencies { implementation project(path: ':ktx') implementation project(path: ':core') implementation project(path: ':rxjava2') } 2 . Using the RxBackoff har, make sure to add RxBackoff.har file in the entry/libs folder and add the below dependency in build.gradle. Modify the dependencies in the entry/build.gradle file. dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) } 3 . For using RxBackoff from a remote repository in separate application, add the below dependency in build.gradle file. Modify ktx/build.gradle as below : ```gradle dependencies { implementation 'io.openharmony.tpc.thirdlib:RxBackoff-core:1.0.1' } ``` Modify rxjava2/build.gradle as below : ```gradle dependencies { api 'io.openharmony.tpc.thirdlib:RxBackoff-core:1.0.1' } ``` Modify entry/build.gradle as below : ```gradle dependencies { implementation 'io.openharmony.tpc.thirdlib:RxBackoff-ktx:1.0.0' api 'io.openharmony.tpc.thirdlib:RxBackoff-rxjava2:1.0.0' } ``` ## License Copyright 2017 Matsumura Yuki. Licensed under the Apache License, Version 2.0;