Skip to content

Commit 7e5e973

Browse files
sebleclercnlutsenko
authored andcommitted
Adding a new executor which takes an escaping closure (BoltsFramework#58)
1 parent 056a069 commit 7e5e973

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Sources/BoltsSwift/Executor.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public enum Executor {
4444
Passes closures to an executing closure.
4545
*/
4646
case closure((() -> Void) -> Void)
47+
48+
/**
49+
Passes escaping closures to an executing closure.
50+
*/
51+
case escapingClosure((@escaping () -> Void) -> Void)
4752

4853
/**
4954
Executes the given closure using the corresponding strategy.
@@ -88,6 +93,8 @@ public enum Executor {
8893
operationQueue.addOperation(closure)
8994
case .closure(let executingClosure):
9095
executingClosure(closure)
96+
case .escapingClosure(let executingEscapingClosure):
97+
executingEscapingClosure(closure)
9198
}
9299
}
93100
}
@@ -108,6 +115,8 @@ extension Executor : CustomStringConvertible, CustomDebugStringConvertible {
108115
return "Executor with NSOperationQueue"
109116
case .closure:
110117
return "Executor with custom closure"
118+
case .escapingClosure:
119+
return "Executor with custom escaping closure"
111120
}
112121
}
113122

@@ -120,6 +129,8 @@ extension Executor : CustomStringConvertible, CustomDebugStringConvertible {
120129
return "\(description): \(queue)"
121130
case .closure(let closure):
122131
return "\(description): \(closure)"
132+
case .escapingClosure(let closure):
133+
return "\(description): \(closure)"
123134
default:
124135
return description
125136
}

Tests/ExecutorTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ class ExecutorTests: XCTestCase {
9393

9494
waitForTestExpectations()
9595
}
96+
97+
func testEscapingClosureExecute() {
98+
let expectation = self.expectation(description: currentTestName)
99+
100+
Executor.escapingClosure { closure in
101+
closure()
102+
}.execute { () -> Void in
103+
expectation.fulfill()
104+
}
105+
106+
waitForTestExpectations()
107+
}
96108

97109
func testOperationQueueExecute() {
98110
let expectation = self.expectation(description: currentTestName)

0 commit comments

Comments
 (0)