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

Adding a new executor which takes an escaping closure #58

Merged
merged 1 commit into from
May 3, 2017
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
11 changes: 11 additions & 0 deletions Sources/BoltsSwift/Executor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public enum Executor {
Passes closures to an executing closure.
*/
case closure((() -> Void) -> Void)

/**
Passes escaping closures to an executing closure.
*/
case escapingClosure((@escaping () -> Void) -> Void)

/**
Executes the given closure using the corresponding strategy.
Expand Down Expand Up @@ -88,6 +93,8 @@ public enum Executor {
operationQueue.addOperation(closure)
case .closure(let executingClosure):
executingClosure(closure)
case .escapingClosure(let executingEscapingClosure):
executingEscapingClosure(closure)
}
}
}
Expand All @@ -108,6 +115,8 @@ extension Executor : CustomStringConvertible, CustomDebugStringConvertible {
return "Executor with NSOperationQueue"
case .closure:
return "Executor with custom closure"
case .escapingClosure:
return "Executor with custom escaping closure"
}
}

Expand All @@ -120,6 +129,8 @@ extension Executor : CustomStringConvertible, CustomDebugStringConvertible {
return "\(description): \(queue)"
case .closure(let closure):
return "\(description): \(closure)"
case .escapingClosure(let closure):
return "\(description): \(closure)"
default:
return description
}
Expand Down
12 changes: 12 additions & 0 deletions Tests/ExecutorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ class ExecutorTests: XCTestCase {

waitForTestExpectations()
}

func testEscapingClosureExecute() {
let expectation = self.expectation(description: currentTestName)

Executor.escapingClosure { closure in
closure()
}.execute { () -> Void in
expectation.fulfill()
}

waitForTestExpectations()
}

func testOperationQueueExecute() {
let expectation = self.expectation(description: currentTestName)
Expand Down