File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Tests/SentryTests/Swift/Extensions Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -5,9 +5,11 @@ extension NSLock {
55 /// Executes the closure while acquiring the lock.
66 ///
77 /// - Parameter closure: The closure to run.
8- func synchronized( _ closure: ( ) throws -> Void ) rethrows {
9- self . lock ( )
8+ ///
9+ /// - Returns: The value the closure generated.
10+ func synchronized< T> ( _ closure: ( ) throws -> T ) rethrows -> T {
1011 defer { self . unlock ( ) }
11- try closure ( )
12+ self . lock ( )
13+ return try closure ( )
1214 }
1315}
Original file line number Diff line number Diff line change @@ -10,12 +10,18 @@ final class NSLockTests: XCTestCase {
1010 var value = 0
1111
1212 testConcurrentModifications ( asyncWorkItems: 10 , writeLoopCount: 9 , writeWork: { _ in
13+ let returnValue : Int = lock. synchronized {
14+ value += 1
15+ return 10
16+ }
17+ expect ( returnValue) == 10
18+
1319 lock. synchronized {
1420 value += 1
1521 }
1622 } )
1723
18- expect ( value) == 100
24+ expect ( value) == 200
1925 }
2026
2127 func testUnlockWhenThrowing( ) throws {
You can’t perform that action at this time.
0 commit comments