@@ -8,8 +8,8 @@ import _CJavaScriptKit // For swjs_get_worker_thread_id
8
8
func isMainThread( ) -> Bool
9
9
10
10
final class WebWorkerTaskExecutorTests : XCTestCase {
11
- override func setUp( ) {
12
- WebWorkerTaskExecutor . installGlobalExecutor ( )
11
+ override func setUp( ) async {
12
+ await WebWorkerTaskExecutor . installGlobalExecutor ( )
13
13
}
14
14
15
15
func testTaskRunOnMainThread( ) async throws {
@@ -152,48 +152,46 @@ final class WebWorkerTaskExecutorTests: XCTestCase {
152
152
153
153
func testThreadLocalPerThreadValues( ) async throws {
154
154
struct Check {
155
- @ThreadLocal ( boxing: ( ) )
156
- static var value : Int ?
155
+ static let value = ThreadLocal < Int > ( boxing: ( ) )
157
156
}
158
157
let executor = try await WebWorkerTaskExecutor ( numberOfThreads: 1 )
159
- XCTAssertNil ( Check . value)
160
- Check . value = 42
161
- XCTAssertEqual ( Check . value, 42 )
158
+ XCTAssertNil ( Check . value. wrappedValue )
159
+ Check . value. wrappedValue = 42
160
+ XCTAssertEqual ( Check . value. wrappedValue , 42 )
162
161
163
162
let task = Task ( executorPreference: executor) {
164
- XCTAssertEqual ( Check . value, nil )
165
- Check . value = 100
166
- XCTAssertEqual ( Check . value, 100 )
167
- return Check . value
163
+ XCTAssertNil ( Check . value. wrappedValue )
164
+ Check . value. wrappedValue = 100
165
+ XCTAssertEqual ( Check . value. wrappedValue , 100 )
166
+ return Check . value. wrappedValue
168
167
}
169
168
let result = await task. value
170
169
XCTAssertEqual ( result, 100 )
171
- XCTAssertEqual ( Check . value, 42 )
170
+ XCTAssertEqual ( Check . value. wrappedValue , 42 )
172
171
executor. terminate ( )
173
172
}
174
173
175
174
func testLazyThreadLocalPerThreadInitialization( ) async throws {
176
175
struct Check {
177
- static var valueToInitialize = 42
178
- static var countOfInitialization = 0
179
- @ LazyThreadLocal ( initialize: {
176
+ nonisolated ( unsafe ) static var valueToInitialize = 42
177
+ nonisolated ( unsafe ) static var countOfInitialization = 0
178
+ static let value = LazyThreadLocal < Int > ( initialize: {
180
179
countOfInitialization += 1
181
180
return valueToInitialize
182
181
} )
183
- static var value : Int
184
182
}
185
183
let executor = try await WebWorkerTaskExecutor ( numberOfThreads: 1 )
186
184
XCTAssertEqual ( Check . countOfInitialization, 0 )
187
- XCTAssertEqual ( Check . value, 42 )
185
+ XCTAssertEqual ( Check . value. wrappedValue , 42 )
188
186
XCTAssertEqual ( Check . countOfInitialization, 1 )
189
187
190
188
Check . valueToInitialize = 100
191
189
192
190
let task = Task ( executorPreference: executor) {
193
191
XCTAssertEqual ( Check . countOfInitialization, 1 )
194
- XCTAssertEqual ( Check . value, 100 )
192
+ XCTAssertEqual ( Check . value. wrappedValue , 100 )
195
193
XCTAssertEqual ( Check . countOfInitialization, 2 )
196
- return Check . value
194
+ return Check . value. wrappedValue
197
195
}
198
196
let result = await task. value
199
197
XCTAssertEqual ( result, 100 )
0 commit comments