Skip to content

Commit f6071f6

Browse files
committed
opened _currentContext
1 parent 159b1d9 commit f6071f6

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

ExecutionContext/CustomExecutionContext.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public class CustomExecutionContext : ExecutionContextBase, ExecutionContextProt
2727

2828
public func async(task:@escaping SafeTask) {
2929
executor {
30-
let context = currentContext.value
30+
let context = _currentContext.value
3131
defer {
32-
currentContext.value = context
32+
_currentContext.value = context
3333
}
34-
currentContext.value = self
34+
_currentContext.value = self
3535

3636
task()
3737
}

ExecutionContext/DispatchExecutionContext.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@
4545
self.loop = DispatchRunLoop(queue: queue)
4646
super.init()
4747
loop.execute {
48-
currentContext.value = self
48+
_currentContext.value = self
4949
}
5050
}
5151

5252
public func async(task:@escaping SafeTask) {
5353
loop.execute {
54-
currentContext.value = self
54+
_currentContext.value = self
5555
task()
5656
}
5757
}
5858

5959
public func async(after:Timeout, task:@escaping SafeTask) {
6060
loop.execute(delay: after) {
61-
currentContext.value = self
61+
_currentContext.value = self
6262
task()
6363
}
6464
}
@@ -69,7 +69,7 @@
6969
}
7070

7171
return try loop.sync {
72-
currentContext.value = self
72+
_currentContext.value = self
7373
return try task()
7474
}
7575
}

ExecutionContext/ExecutionContext.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,20 @@ public func executionContext(executor:@escaping Executor) -> ExecutionContextPro
192192
return CustomExecutionContext(executor: executor)
193193
}
194194

195-
var currentContext = try! ThreadLocal<ExecutionContextProtocol>()
195+
//Never use it directly
196+
public var _currentContext = try! ThreadLocal<ExecutionContextProtocol>()
196197

197198
public extension ExecutionContextProtocol {
198199
public static var current:ExecutionContextProtocol {
199200
get {
200201
if Thread.isMain {
201202
return ExecutionContext.main
202203
}
203-
if nil == currentContext.value {
204+
if nil == _currentContext.value {
204205
//TODO: think
205206
// currentContext.value = RunLoopExecutionContext(inner: <#T##ExecutionContextType#>)
206207
}
207-
return currentContext.value!
208+
return _currentContext.value!
208209
}
209210
}
210211
}

ExecutionContext/ImmediateExecutionContext.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import Boilerplate
1919

2020
class ImmediateExecutionContext : ExecutionContextBase, ExecutionContextProtocol {
2121
func async(task:@escaping SafeTask) {
22-
let context = currentContext.value
22+
let context = _currentContext.value
2323
defer {
24-
currentContext.value = context
24+
_currentContext.value = context
2525
}
26-
currentContext.value = self
26+
_currentContext.value = self
2727

2828
task()
2929
}
@@ -36,11 +36,11 @@ class ImmediateExecutionContext : ExecutionContextBase, ExecutionContextProtocol
3636
}
3737

3838
func sync<ReturnType>(task:@escaping TaskWithResult<ReturnType>) rethrows -> ReturnType {
39-
let context = currentContext.value
39+
let context = _currentContext.value
4040
defer {
41-
currentContext.value = context
41+
_currentContext.value = context
4242
}
43-
currentContext.value = self
43+
_currentContext.value = self
4444

4545
return try task()
4646
}

ExecutionContext/RunLoopExecutionContext.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ public class RunLoopExecutionContext : ExecutionContextBase, ExecutionContextPro
153153

154154
public func async(task:@escaping SafeTask) {
155155
inner.async {
156-
currentContext.value = self
156+
_currentContext.value = self
157157
task()
158158
}
159159
}
160160

161161
public func async(after:Timeout, task:@escaping SafeTask) {
162162
inner.async(after: after) {
163-
currentContext.value = self
163+
_currentContext.value = self
164164
task()
165165
}
166166
}
@@ -170,7 +170,7 @@ public class RunLoopExecutionContext : ExecutionContextBase, ExecutionContextPro
170170
return try task()
171171
}
172172
return try inner.sync {
173-
currentContext.value = self
173+
_currentContext.value = self
174174
return try task()
175175
}
176176
}

0 commit comments

Comments
 (0)