Skip to content

Commit 22a5a2b

Browse files
committed
Merge remote-tracking branch 'reactive-swift/master' into develop
2 parents 6a92190 + 93854b5 commit 22a5a2b

17 files changed

+223
-253
lines changed

Cartfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
github "antitypical/Result" ~> 2.0
2-
github "crossroadlabs/Boilerplate" ~> 0.1
3-
github "reactive-swift/RunLoop" "master"
1+
github "crossroadlabs/Boilerplate" ~> 1.0
2+
github "reactive-swift/RunLoop" ~> 1.0

Cartfile.private

Lines changed: 0 additions & 1 deletion
This file was deleted.

ExecutionContext.xcodeproj/project.pbxproj

Lines changed: 16 additions & 37 deletions
Large diffs are not rendered by default.

ExecutionContext.xcodeproj/xcshareddata/xcschemes/ExecutionContext-OSX.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0720"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

ExecutionContext.xcodeproj/xcshareddata/xcschemes/ExecutionContext-iOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0730"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

ExecutionContext.xcodeproj/xcshareddata/xcschemes/ExecutionContext-tvOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0730"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

ExecutionContext.xcodeproj/xcshareddata/xcschemes/ExecutionContext-watchOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0730"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

ExecutionContext/CustomExecutionContext.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
import Foundation
18-
import Foundation3
1918
import Boilerplate
2019

21-
public class CustomExecutionContext : ExecutionContextBase, ExecutionContextType {
20+
public class CustomExecutionContext : ExecutionContextBase, ExecutionContextProtocol {
2221
let id = NSUUID()
2322
let executor:Executor
2423

25-
public init(executor:Executor) {
24+
public init(executor:@escaping Executor) {
2625
self.executor = executor
2726
}
2827

29-
public func async(task:SafeTask) {
28+
public func async(task:@escaping SafeTask) {
3029
executor {
3130
let context = currentContext.value
3231
defer {
@@ -38,21 +37,21 @@ public class CustomExecutionContext : ExecutionContextBase, ExecutionContextType
3837
}
3938
}
4039

41-
public func async(after:Timeout, task:SafeTask) {
40+
public func async(after:Timeout, task:@escaping SafeTask) {
4241
async {
43-
Thread.sleep(after)
42+
Thread.sleep(timeout: after)
4443
task()
4544
}
4645
}
4746

48-
public func sync<ReturnType>(task:() throws -> ReturnType) rethrows -> ReturnType {
49-
return try syncThroughAsync(task)
47+
public func sync<ReturnType>(task:@escaping TaskWithResult<ReturnType>) rethrows -> ReturnType {
48+
return try syncThroughAsync(task: task)
5049
}
5150

52-
public func isEqualTo(other: NonStrictEquatable) -> Bool {
51+
public func isEqual(to other: NonStrictEquatable) -> Bool {
5352
guard let other = other as? CustomExecutionContext else {
5453
return false
5554
}
5655
return id.isEqual(other.id)
5756
}
58-
}
57+
}

ExecutionContext/DefaultExecutionContext.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import Foundation
1818

1919
#if !os(Linux) || dispatch
2020

21-
#if nouv
22-
public typealias DefaultExecutionContext = DispatchExecutionContext
23-
#else
21+
#if uv
2422
public typealias DefaultExecutionContext = RunLoopExecutionContext
23+
#else
24+
public typealias DefaultExecutionContext = DispatchExecutionContext
2525
#endif
2626

2727
#else
@@ -36,18 +36,17 @@ import Foundation
3636

3737
#endif
3838

39-
public protocol DefaultExecutionContextType : ExecutionContextType {
39+
public protocol DefaultExecutionContextProtocol : ExecutionContextProtocol {
4040
init(kind:ExecutionContextKind)
4141

42-
static var main:ExecutionContextType {
42+
static var main:ExecutionContextProtocol {
4343
get
4444
}
4545

46-
static var global:ExecutionContextType {
46+
static var global:ExecutionContextProtocol {
4747
get
4848
}
4949

5050
/// unfortunately name main() is not allowed
51-
@noreturn
52-
static func mainProc()
53-
}
51+
static func mainProc() -> Never
52+
}

ExecutionContext/DispatchExecutionContext.swift

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,53 @@
1717
#if !os(Linux) || dispatch
1818

1919
import Foundation
20-
import Foundation3
2120
import Dispatch
2221
import Boilerplate
2322
import RunLoop
2423

2524
private extension ExecutionContextKind {
26-
func createDispatchQueue(id:String) -> dispatch_queue_t! {
25+
func createDispatchQueue(id:String) -> DispatchQueue {
2726
switch self {
2827
case .serial:
29-
return dispatch_queue_create(id, DISPATCH_QUEUE_SERIAL)
28+
return DispatchQueue(label: id)
3029
case .parallel:
31-
return dispatch_queue_create(id, DISPATCH_QUEUE_CONCURRENT)
30+
return DispatchQueue(label: id, attributes: .concurrent)
3231
}
3332
}
3433
}
3534

36-
public class DispatchExecutionContext : ExecutionContextBase, ExecutionContextType, DefaultExecutionContextType {
35+
public class DispatchExecutionContext : ExecutionContextBase, ExecutionContextProtocol, DefaultExecutionContextProtocol {
3736
private let loop:DispatchRunLoop
3837

3938
public required convenience init(kind:ExecutionContextKind) {
4039
let id = NSUUID().uuidString
41-
let queue = kind.createDispatchQueue(id)
40+
let queue = kind.createDispatchQueue(id: id)
4241
self.init(queue: queue)
4342
}
4443

45-
public init(queue:dispatch_queue_t) {
44+
public init(queue:DispatchQueue) {
4645
self.loop = DispatchRunLoop(queue: queue)
4746
super.init()
4847
loop.execute {
4948
currentContext.value = self
5049
}
5150
}
5251

53-
public func async(task:SafeTask) {
52+
public func async(task:@escaping SafeTask) {
5453
loop.execute {
5554
currentContext.value = self
5655
task()
5756
}
5857
}
5958

60-
public func async(after:Timeout, task:SafeTask) {
61-
loop.execute(after) {
59+
public func async(after:Timeout, task:@escaping SafeTask) {
60+
loop.execute(delay: after) {
6261
currentContext.value = self
6362
task()
6463
}
6564
}
6665

67-
public func sync<ReturnType>(task:() throws -> ReturnType) rethrows -> ReturnType {
66+
public func sync<ReturnType>(task:@escaping TaskWithResult<ReturnType>) rethrows -> ReturnType {
6867
if isCurrent {
6968
return try task()
7069
}
@@ -75,24 +74,23 @@
7574
}
7675
}
7776

78-
public static let main:ExecutionContextType = DispatchExecutionContext(queue: dispatch_get_main_queue())
79-
public static let global:ExecutionContextType = DispatchExecutionContext(queue: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0))
77+
public static let main:ExecutionContextProtocol = DispatchExecutionContext(queue: .main)
78+
public static let global:ExecutionContextProtocol = DispatchExecutionContext(queue: .global())
8079

81-
@noreturn
82-
public static func mainProc() {
80+
public static func mainProc() -> Never {
8381
if !Thread.isMain {
8482
print("Main proc was called on non-main thread. Exiting")
8583
exit(1)
8684
}
87-
dispatch_main()
85+
dispatchMain()
8886
}
8987

90-
public func isEqualTo(other: NonStrictEquatable) -> Bool {
88+
public func isEqual(to other: NonStrictEquatable) -> Bool {
9189
guard let other = other as? DispatchExecutionContext else {
9290
return false
9391
}
94-
return loop.isEqualTo(other.loop)
92+
return loop.isEqual(to: other.loop)
9593
}
9694
}
9795

98-
#endif
96+
#endif

0 commit comments

Comments
 (0)