Skip to content

Commit

Permalink
Merge pull request #42 from iZettle/abort-repeat-fix
Browse files Browse the repository at this point in the history
Bugfix: Updated `Future.abort(forFutures:)` to more correctly handl…
  • Loading branch information
mansbernhardt authored Oct 12, 2018
2 parents 42e6806 + a3e32f8 commit 4026b30
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.3.1

- Bugfix: Updated `Future.abort(forFutures:)` to more correctly handle repetition.

# 1.3

- Added versions of `bindTo()` that can bind a non optional to an optional value.
Expand Down
6 changes: 3 additions & 3 deletions Flow/Future+Combiners.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ public extension Future {
/// The returned future completes when either `self` of any of the `futures` completes, whichever completes first.
/// If any of the futures in `futures` completes first the returned future will always fail with either the future's error or `FutureError.aborted` if it completes successfully.
func abort(forFutures futures: [Future<()>]) -> Future {
return Future { completion in
let future = self.onResult(on: .none, completion)
return Future { completion, mover in
let future = mover.moveInside(self).onResult(on: .none, completion)

let aborts = Flow.select(between: futures).onResult(on: .none) { result in
let aborts = Flow.select(between: futures.map(mover.moveInside)).onResult(on: .none) { result in
completion(.failure(result.error ?? FutureError.aborted))
}

Expand Down
12 changes: 12 additions & 0 deletions FlowTests/FutureUtilitiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ class FutureUtilitiesTests: FutureTest {
}
}

func testAbortForFuturesRepeat() {
let e = errorExpectation()
e.expectedFulfillmentCount = 4
testFuture(timeout: 2) {
Future()
.onValue { e.fulfill() }
.delay(by: 10).abort(forFutures: [ Future().onValue { e.fulfill() }.delay(by: 0.1) ])
.mapResult { _ in () }
.repeatAndCollect(repeatCount: 1)
}
}

func testIgnoreAbort() {
testFuture(timeout: 1, cancelAfterDelay: 0.1) { () -> Future<Int> in
let e = errorExpectation()
Expand Down

0 comments on commit 4026b30

Please sign in to comment.