Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Commit

Permalink
Stylistic autocorrection for Swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
zwaldowski committed Feb 23, 2018
1 parent c0febcd commit 418cb57
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Sources/Task/ExistentialTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public final class Task<SuccessValue>: NSObject {
extension Task: FutureProtocol {
public typealias Value = Result

public func upon(_ queue: PreferredExecutor, execute body: @escaping(Result) -> ()) {
public func upon(_ queue: PreferredExecutor, execute body: @escaping(Result) -> Void) {
future.upon(queue, execute: body)
}

public func upon(_ executor: Executor, execute body: @escaping(Result) -> ()) {
public func upon(_ executor: Executor, execute body: @escaping(Result) -> Void) {
future.upon(executor, execute: body)
}

Expand Down
1 change: 0 additions & 1 deletion Sources/Task/ResultPromise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ extension PromiseProtocol where Value: Either, Value.Right == Void {
return succeed(with: ())
}
}

5 changes: 2 additions & 3 deletions Sources/Task/TaskProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private final class ProxyProgress: Progress {
return [ #keyPath(observee.userInfo) ]
}

override var userInfo: [ProgressUserInfoKey : Any] {
override var userInfo: [ProgressUserInfoKey: Any] {
return observee.userInfo
}

Expand Down Expand Up @@ -136,7 +136,7 @@ private final class ProxyProgress: Progress {
observee.removeObserver(self, forKeyPath: #keyPath(Progress.paused), context: Observation.pausedContext)
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
guard let keyPath = keyPath, object != nil, bnr_atomic_bitmask_test(&state, State.ready.rawValue), let observer = observer, let newValue = change?[.newKey] else { return }
switch context {
case Observation.cancelledContext?:
Expand Down Expand Up @@ -318,4 +318,3 @@ extension Task {
}

#endif

10 changes: 5 additions & 5 deletions Sources/Task/TaskRecovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension Task {
public func recover(upon executor: PreferredExecutor, substituting substitution: @escaping(Error) throws -> SuccessValue) -> Task<SuccessValue> {
return recover(upon: executor as Executor, substituting: substitution)
}

/// Returns a `Task` containing the result of mapping `substitution` over
/// the failed task's error.
///
Expand Down Expand Up @@ -57,7 +57,7 @@ extension Task {
return Task<SuccessValue>(future: future, cancellation: cancel)
#endif
}

/// Begins another task in the case of the failure of `self` by calling
/// `restartTask` with the error.
///
Expand All @@ -69,7 +69,7 @@ extension Task {
public func fallback<NewTask: FutureProtocol>(upon executor: PreferredExecutor, to restartTask: @escaping(Error) -> NewTask) -> Task<SuccessValue> where NewTask.Value: Either, NewTask.Value.Left == Error, NewTask.Value.Right == SuccessValue {
return fallback(upon: executor as Executor, to: restartTask)
}

/// Begins another task in the case of the failure of `self` by calling
/// `restartTask` with the error.
///
Expand All @@ -87,13 +87,13 @@ extension Task {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
let progress = extendedProgress(byUnitCount: 1)
#endif

let future: Future<Result> = andThen(upon: executor) { (result) -> Task<SuccessValue> in
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
progress.becomeCurrent(withPendingUnitCount: 1)
defer { progress.resignCurrent() }
#endif

do {
let value = try result.extract()
return Task(success: value)
Expand Down
1 change: 0 additions & 1 deletion Sources/Task/TaskResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,3 @@ extension Task.Result where SuccessValue == Void {
}

}

2 changes: 1 addition & 1 deletion Tests/DeferredTests/ExistentialFutureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ExistentialFutureTests: XCTestCase {
("testAnyWaitWithTimeout", testAnyWaitWithTimeout),
("testFilledAnyFutureUpon", testFilledAnyFutureUpon),
("testUnfilledAnyUponCalledWhenFilled", testUnfilledAnyUponCalledWhenFilled),
("testFillAndIsFilledPostcondition", testFillAndIsFilledPostcondition),
("testFillAndIsFilledPostcondition", testFillAndIsFilledPostcondition)
]
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/DeferredTests/FutureCustomExecutorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FutureCustomExecutorTests: CustomExecutorTestCase {
return [
("testUpon", testUpon),
("testMap", testMap),
("testAndThen", testAndThen),
("testAndThen", testAndThen)
]
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/DeferredTests/FutureIgnoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FutureIgnoreTests: XCTestCase {
static var allTests: [(String, (FutureIgnoreTests) -> () throws -> Void)] {
return [
("testWaitWithTimeout", testWaitWithTimeout),
("testIgnoredUponCalledWhenFilled", testIgnoredUponCalledWhenFilled),
("testIgnoredUponCalledWhenFilled", testIgnoredUponCalledWhenFilled)
]
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/DeferredTests/FutureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FutureTests: XCTestCase {
("testAnd", testAnd),
("testAllFilled", testAllFilled),
("testAllFilledEmptyCollection", testAllFilledEmptyCollection),
("testFirstFilled", testFirstFilled),
("testFirstFilled", testFirstFilled)
]
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/DeferredTests/LockingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class LockingTests: XCTestCase {
for lock in allLocks {
var x = UnsafeAtomicCounter()

let startReader: (Int) -> () = { i in
let startReader: (Int) -> Void = { i in
let expectation = self.expectation(description: "reader \(i)")
self.queue.async {
lock.withReadLock {
Expand Down Expand Up @@ -158,7 +158,7 @@ class LockingTests: XCTestCase {
}

func measureReadsSingleThread(lock: Locking, iterations: Int, file: StaticString = #file, line: Int = #line) {
let doNothing: () -> () = {}
let doNothing: () -> Void = {}
func body() {
for _ in 0 ..< iterations {
lock.withReadLock(doNothing)
Expand All @@ -173,7 +173,7 @@ class LockingTests: XCTestCase {
}

func measureWritesSingleThread(lock: Locking, iterations: Int, file: StaticString = #file, line: Int = #line) {
let doNothing: () -> () = {}
let doNothing: () -> Void = {}
func body() {
for _ in 0 ..< iterations {
lock.withWriteLock(doNothing)
Expand Down
6 changes: 3 additions & 3 deletions Tests/DeferredTests/ProtectedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class ProtectedTests: XCTestCase {
func testConcurrentReadingWriting() {
var lastWriterDate: Date?

let startReader: (Int) -> () = { iteration in
let startReader: (Int) -> Void = { iteration in
let expectation = self.expectation(description: "reader \(iteration)")
self.queue.async {
self.protected.withReadLock { (arg) -> () in
self.protected.withReadLock { (arg) -> Void in
let (date, items) = arg
if items.isEmpty && date == nil {
// OK - we're before the writer has added items
Expand All @@ -59,7 +59,7 @@ class ProtectedTests: XCTestCase {
}
let expectation = self.expectation(description: "writer")
self.queue.async {
self.protected.withWriteLock { dateItemsTuple -> () in
self.protected.withWriteLock { dateItemsTuple -> Void in
for i in 0 ..< 5 {
dateItemsTuple.0 = Date()
dateItemsTuple.1.append(i)
Expand Down
2 changes: 1 addition & 1 deletion Tests/DeferredTests/SwiftBugTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SwiftBugTests: XCTestCase {
let toBeFilledWith: [SomeMultipayloadEnum: SomeMultipayloadEnum] = [
keys[0]: .two("one"),
keys[1]: .two("two"),
keys[2]: .two("three"),
keys[2]: .two("three")
]

let expect = expectation(description: "upon is called with correct values")
Expand Down
2 changes: 1 addition & 1 deletion Tests/TaskTests/ResultRecoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ResultRecoveryTests: XCTestCase {
static var allTests: [(String, (ResultRecoveryTests) -> () throws -> Void)] {
return [
("testInitWithFunctionProducesSuccesses", testInitWithFunctionProducesSuccesses),
("testInitWithFunctionProducesFailures", testInitWithFunctionProducesFailures),
("testInitWithFunctionProducesFailures", testInitWithFunctionProducesFailures)
]
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/TaskTests/TaskComprehensiveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TaskComprehensiveTests: XCTestCase {
static var allTests: [(String, (TaskComprehensiveTests) -> () throws -> Void)] {
return [
("testThatSeveralIterationsRunCorrectly", testThatSeveralIterationsRunCorrectly),
("testThatCancellingATaskPropagatesTheCancellation", testThatCancellingATaskPropagatesTheCancellation),
("testThatCancellingATaskPropagatesTheCancellation", testThatCancellingATaskPropagatesTheCancellation)
]
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/TaskTests/TaskGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Deferred
class TaskGroupTests: XCTestCase {
static var allTests: [(String, (TaskGroupTests) -> () throws -> Void)] {
return [
("testThatAllCompleteTaskWaitsForAllAccumulatedTasks", testThatAllCompleteTaskWaitsForAllAccumulatedTasks),
("testThatAllCompleteTaskWaitsForAllAccumulatedTasks", testThatAllCompleteTaskWaitsForAllAccumulatedTasks)
]
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/TaskTests/TaskResultTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TaskResultTests: XCTestCase {
XCTAssertEqual(x.value, 84)
XCTAssertNil(x.error)
}

func testInitializeWithBlockSuccess() {
let result = Result(value: 42, error: nil)
XCTAssertEqual(try? result.extract(), 42)
Expand Down
8 changes: 4 additions & 4 deletions Tests/TaskTests/TaskTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,20 @@ class TaskTests: CustomExecutorTestCase {
waitForExpectations()
assertExecutorCalled(atLeast: 1)
}

#endif

func testThatFallbackAlsoProducesANewTask() {
let expectation = self.expectation(description: "recover produces a new task")
let task: Task<Int> = anyFailedTask.fallback(upon: executor) { _ in
return self.anyFinishedTask
}

task.upon {
XCTAssertEqual($0.value, 42)
expectation.fulfill()
}

waitForExpectations()
assertExecutorCalled(2)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/TaskTests/TaskWorkItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TaskWorkItemTests: XCTestCase {
static var allTests: [(String, (TaskWorkItemTests) -> () throws -> Void)] {
return [
("testThatCancellingATaskAfterItStartsRunningIsANoop", testThatCancellingATaskAfterItStartsRunningIsANoop),
("testThatCancellingBeforeATaskStartsProducesTheCancellationError", testThatCancellingBeforeATaskStartsProducesTheCancellationError),
("testThatCancellingBeforeATaskStartsProducesTheCancellationError", testThatCancellingBeforeATaskStartsProducesTheCancellationError)
]
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/TaskTests/VoidResultTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class VoidResultTests: XCTestCase {
("testDescriptionFailure", testDescriptionFailure),
("testDebugDescriptionSuccess", testDebugDescriptionSuccess),
("testDebugDescriptionFailure", testDebugDescriptionFailure),
("testExtract", testExtract),
("testExtract", testExtract)
]
}

Expand Down

0 comments on commit 418cb57

Please sign in to comment.