RxSwiftAutoRetry is an extension to RxSwift - a well-known Reactive Swift framework. It allows user to retry observable after exponential time. It also provides simple way to randomize time of delay.
To run the example project, clone the repo, and run pod install
from the root project directory first.
To run tests, run carthage update
from the root project directory first.
- iOS 8.0+
- macOS 10.9+
CocoaPods is a dependency manager, which simplifies adding 3rd-party libraries. To install it, add the following line to your Podfile:
pod 'RxSwiftAutoRetry'
Then, you need to run below comand to install framework into your project:
pod install
Carthage is decentralized dependency manager which allows you to keep your dependencies in compiled format.
- To install it, add following line to your Cartfile:
github 'SwingDev/RxSwiftAutoRetry'
- Next, run
carthage update
- On your application targets’ Build Phases tab, in the Link Binary With Libraries section, drag and drop
RxSwift.framework
andRxSwiftAutoRetry.framework
from the Carthage/Build folder on disk. - On your application targets’ Build Phases settings tab, click the + icon and choose New Run Script Phase. Create a Run Script in which you specify your shell (ex: /bin/sh), add the following contents to the script area below the shell:
/usr/local/bin/carthage copy-frameworks
- Add the paths to the frameworks you want to use under “Input Files". For example:
$(SRCROOT)/Carthage/Build/<platform>/RxSwift.framework
$(SRCROOT)/Carthage/Build/<platform>/RxSwiftAutoRetry.framework
Swift Package Manager is is a tool for managing the distribution of Swift code and integrating it into compiler.
It only works with macOS.
Add dependency to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/SwingDev/RxSwiftAutoRetry.git", from: "0.9"))
]
Then, run below command:
pod install
See sample project in Example folder.
retryExponentially
is extension method for RxSwift framework (in case to use this method please import RxSwift library.)
Usually using this method looks like it:
observable.retryExponentially()
This method provides set of default values for parameters so its behavior can be customized:
observable.retryExponentially(2, with: 0.9...1.1, scheduler: scheduler) { error in
//Add code
}
- maxAttemptCount - Maximum number of times to repeat the sequence.
- jitter - Multiplier which randomize delay time. Randomizing value is chosen from given range.
- scheduler - Scheduler on which the delay will be conducted
- onRetry - Action which will be invoked after delay on every retry. This is optional parameter.
- maxAttemptCount:
3
- jitter:
0.9...1.1
- scheduler:
ConcurrentDispatchQueueScheduler(queue: DispatchQueue.global())
- onRetry:
nil
RxSwiftAutoRetry is available under the MIT license. See the LICENSE file for more info.