Skip to content

Commit

Permalink
Add if argument to retry(when:) operator.
Browse files Browse the repository at this point in the history
  • Loading branch information
srdanrasic committed Oct 12, 2017
1 parent 9960421 commit 4fc13a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ReactiveKit.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = "ReactiveKit"
s.version = "3.7.4"
s.version = "3.7.5"
s.summary = "A Swift Reactive Programming Framework"
s.description = "ReactiveKit is a Swift framework for reactive and functional reactive programming."
s.homepage = "https://github.com/ReactiveKit/ReactiveKit"
s.license = 'MIT'
s.author = { "Srdan Rasic" => "srdan.rasic@gmail.com" }
s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v3.7.4" }
s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v3.7.5" }

s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.9'
Expand Down
2 changes: 1 addition & 1 deletion ReactiveKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.7.4</string>
<string>3.7.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
22 changes: 14 additions & 8 deletions Sources/SignalProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,9 @@ extension SignalProtocol {
}

/// Retries the failed signal when other signal produces an element.
public func retry<S: SignalProtocol>(when other: S) -> Signal<Element, Error> where S.Error == NoError {
/// - parameter other: Signal that triggers a retry attempt.
/// - parameter shouldRetry: Retries only if this returns true for a given error. Defaults to always returning true.
public func retry<S: SignalProtocol>(when other: S, if shouldRetry: @escaping (Error) -> Bool = { _ in true }) -> Signal<Element, Error> where S.Error == NoError {
return Signal { observer in
let serialDisposable = SerialDisposable(otherDisposable: nil)
var attempt: (() -> Void)?
Expand All @@ -1027,14 +1029,18 @@ extension SignalProtocol {
attempt = nil
observer.completed()
case .failed(let error):
compositeDisposable += other.observe { otherEvent in
switch otherEvent {
case .next:
attempt?()
case .completed, .failed:
attempt = nil
observer.failed(error)
if shouldRetry(error) {
compositeDisposable += other.observe { otherEvent in
switch otherEvent {
case .next:
attempt?()
case .completed, .failed:
attempt = nil
observer.failed(error)
}
}
} else {
observer.failed(error)
}
}
}
Expand Down

0 comments on commit 4fc13a7

Please sign in to comment.