Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out errors from CompletableAction.completions #236

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
Current master
--------------

- Avoid from getting errors in `CompletableAction.completions`
- Break retain cycle in `bind(to:input:)`
- Use PublishRelay instead of PublishSubject

Expand Down
8 changes: 5 additions & 3 deletions Sources/Action/Action+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public extension CompletableAction {
var completions: Observable<Void> {
return executionObservables
.flatMap { execution in
execution.flatMap { _ in Observable.empty() }
.concat(Observable.just(()))
}
execution.flatMap { _ in Observable<Void?>.empty() }
.concat(Observable<Void?>.just(()))
.catchAndReturn(nil)
}
.compactMap { $0 }
}
}
27 changes: 27 additions & 0 deletions Tests/ActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,33 @@ class ActionTests: QuickSpec {
expect(completions.events.contains { $0.time == 20}).to(beTrue())
}
}
describe("completable action finished with error") {
var action: CompletableAction<Error?>!
beforeEach {
action = CompletableAction { errorMaybe -> Completable in
if let error = errorMaybe {
return Observable<Never>.error(error).asCompletable()
} else {
return Observable<Never>.empty().asCompletable()
}

}
scheduler.scheduleAt(10) { action.inputs.onNext(TestError) }
scheduler.scheduleAt(20) { action.inputs.onNext(nil) }
}
afterEach {
action = nil
}
it("emits no errors on `completions`") {
let completions = scheduler.createObserver(Void.self)
action.completions.bind(to: completions).disposed(by: disposeBag)

scheduler.start()

expect(completions.events.contains { $0.time == 10 }).to(beFalse())
expect(completions.events.contains { $0.time == 20 }).to(beTrue())
}
}

describe("Input observer behavior") {
var action: Action<String, String>!
Expand Down