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

Make all 'trySet', 'set' functions to use explicit argument labels. #30

Merged
merged 1 commit into from
Jun 27, 2016
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
6 changes: 3 additions & 3 deletions Sources/BoltsSwift/Task+ContinueWith.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extension Task {
taskCompletionSource.setState(nextTask.state)
}
case .Error(let error):
taskCompletionSource.setError(error)
taskCompletionSource.set(error: error)
case .Cancelled:
taskCompletionSource.cancel()
default: abort() // This should never happen.
Expand All @@ -54,10 +54,10 @@ extension Task {

case .Success(let result as S):
// This is for continueOnErrorWith - the type of the result doesn't change, so we can pass it through
taskCompletionSource.setResult(result)
taskCompletionSource.set(result: result)

case .Error(let error):
taskCompletionSource.setError(error)
taskCompletionSource.set(error: error)

case .Cancelled:
taskCompletionSource.cancel()
Expand Down
2 changes: 1 addition & 1 deletion Sources/BoltsSwift/Task+Delay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension Task {
let taskCompletionSource = TaskCompletionSource<Void>()
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay * NSTimeInterval(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
taskCompletionSource.trySetResult()
taskCompletionSource.trySet(result: ())
}
return taskCompletionSource.task
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/BoltsSwift/Task+WhenAll.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ extension Task {
if cancelledCount > 0 {
tcs.cancel()
} else if errorCount > 0 {
tcs.setError(AggregateError(errors: tasks.flatMap({ $0.error })))
tcs.set(error: AggregateError(errors: tasks.flatMap({ $0.error })))
} else {
tcs.setResult()
tcs.set(result: ())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/BoltsSwift/Task+WhenAny.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension Task {
break
}
task.continueWith { task in
taskCompletionSource.trySetResult()
taskCompletionSource.trySet(result: ())
}
}
return taskCompletionSource.task
Expand Down
4 changes: 2 additions & 2 deletions Sources/BoltsSwift/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public final class Task<TResult> {
public convenience init(_ executor: Executor = .Default, closure: (Void throws -> TResult)) {
self.init(state: .Pending())
executor.execute {
self.trySetState(TaskState.fromClosure(closure))
self.trySet(state: TaskState.fromClosure(closure))
}
}

Expand Down Expand Up @@ -234,7 +234,7 @@ public final class Task<TResult> {

// MARK: State Change

func trySetState(state: TaskState<TResult>) -> Bool {
func trySet(state state: TaskState<TResult>) -> Bool {
var stateChanged = false

var continuations: [Continuation]?
Expand Down
22 changes: 11 additions & 11 deletions Sources/BoltsSwift/TaskCompletionSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class TaskCompletionSource<TResult> {

- parameter result: The task result.
*/
public func setResult(result: TResult) {
guard task.trySetState(.Success(result)) else {
public func set(result result: TResult) {
guard task.trySet(state: .Success(result)) else {
preconditionFailure("Can not set the result on a completed task.")
}
}
Expand All @@ -59,8 +59,8 @@ public class TaskCompletionSource<TResult> {

- parameter error: The task error.
*/
public func setError(error: ErrorType) {
guard task.trySetState(.Error(error)) else {
public func set(error error: ErrorType) {
guard task.trySet(state: .Error(error)) else {
preconditionFailure("Can not set error on a completed task.")
}
}
Expand All @@ -71,7 +71,7 @@ public class TaskCompletionSource<TResult> {
Throws an exception if the task is already completed.
*/
public func cancel() {
guard task.trySetState(.Cancelled) else {
guard task.trySet(state: .Cancelled) else {
preconditionFailure("Can not cancel a completed task.")
}
}
Expand All @@ -82,8 +82,8 @@ public class TaskCompletionSource<TResult> {
- parameter result: The task result.
- returns: `true` if the result was set, `false` otherwise.
*/
public func trySetResult(result: TResult) -> Bool {
return task.trySetState(.Success(result))
public func trySet(result result: TResult) -> Bool {
return task.trySet(state: .Success(result))
}

/**
Expand All @@ -92,8 +92,8 @@ public class TaskCompletionSource<TResult> {
- parameter error: The task error.
- returns: `true` if the error was set, `false` otherwise.
*/
public func trySetError(error: ErrorType) -> Bool {
return task.trySetState(.Error(error))
public func trySet(error error: ErrorType) -> Bool {
return task.trySet(state: .Error(error))
}

/**
Expand All @@ -102,15 +102,15 @@ public class TaskCompletionSource<TResult> {
- returns: `true` if the task was completed, `false` otherwise.
*/
public func tryCancel() -> Bool {
return task.trySetState(.Cancelled)
return task.trySet(state: .Cancelled)
}

//--------------------------------------
// MARK: - Change Task State (internal)
//--------------------------------------

func setState(state: TaskState<TResult>) {
guard task.trySetState(state) else {
guard task.trySet(state: state) else {
preconditionFailure("Can not complete a completed task.")
}
}
Expand Down
36 changes: 18 additions & 18 deletions Tests/TaskCompletionSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import BoltsSwift
class TaskCompletionSourceTests: XCTestCase {

func testInit() {
let sut = TaskCompletionSource<String>()
let task = sut.task
let tcs = TaskCompletionSource<String>()
let task = tcs.task

XCTAssertFalse(task.completed)
XCTAssertFalse(task.faulted)
Expand All @@ -24,10 +24,10 @@ class TaskCompletionSourceTests: XCTestCase {
}

func testSetResult() {
let sut = TaskCompletionSource<String>()
let task = sut.task
let tcs = TaskCompletionSource<String>()
let task = tcs.task

sut.setResult(currentTestName)
tcs.set(result: currentTestName)

XCTAssertTrue(task.completed)
XCTAssertNotNil(task.result)
Expand All @@ -36,10 +36,10 @@ class TaskCompletionSourceTests: XCTestCase {

func testSetError() {
let error = NSError(domain: "com.bolts", code: 1, userInfo: nil)
let sut = TaskCompletionSource<String>()
let task = sut.task
let tcs = TaskCompletionSource<String>()
let task = tcs.task

sut.setError(error)
tcs.set(error: error)

XCTAssertTrue(task.completed)
XCTAssertTrue(task.faulted)
Expand All @@ -48,10 +48,10 @@ class TaskCompletionSourceTests: XCTestCase {
}

func testCancel() {
let sut = TaskCompletionSource<String>()
let task = sut.task
let tcs = TaskCompletionSource<String>()
let task = tcs.task

sut.cancel()
tcs.cancel()

XCTAssertTrue(task.completed)
XCTAssertTrue(task.cancelled)
Expand All @@ -61,7 +61,7 @@ class TaskCompletionSourceTests: XCTestCase {
let sut = TaskCompletionSource<String>()
let task = sut.task

let success = sut.trySetResult(currentTestName)
let success = sut.trySet(result: currentTestName)

XCTAssertTrue(success)
XCTAssertTrue(task.completed)
Expand All @@ -74,7 +74,7 @@ class TaskCompletionSourceTests: XCTestCase {
let sut = TaskCompletionSource<String>()
let task = sut.task

let success = sut.trySetError(error)
let success = sut.trySet(error: error)

XCTAssertTrue(success)
XCTAssertTrue(task.completed)
Expand All @@ -96,26 +96,26 @@ class TaskCompletionSourceTests: XCTestCase {

func testTrySetResultReturningFalse() {
let sut = TaskCompletionSource<String>()
sut.setResult(currentTestName)
sut.set(result: currentTestName)

let success = sut.trySetResult(currentTestName)
let success = sut.trySet(result: currentTestName)

XCTAssertFalse(success)
}

func testTrySetErrorReturningFalse() {
let error = NSError(domain: "com.bolts", code: 1, userInfo: nil)
let sut = TaskCompletionSource<String>()
sut.setResult(currentTestName)
sut.set(result: currentTestName)

let success = sut.trySetError(error)
let success = sut.trySet(error: error)

XCTAssertFalse(success)
}

func testTryCancelReturningFalse() {
let sut = TaskCompletionSource<String>()
sut.setResult(currentTestName)
sut.set(result: currentTestName)
let success = sut.tryCancel()
XCTAssertFalse(success)
}
Expand Down