Skip to content

Commit

Permalink
Update package
Browse files Browse the repository at this point in the history
  • Loading branch information
vmanot committed Dec 3, 2024
1 parent 6d80c19 commit e06fe31
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 296 deletions.
29 changes: 29 additions & 0 deletions Sources/Merge/Intermodular/Extensions/Foundation/NSLocking++.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Copyright (c) Vatsal Manot
//

import Combine
import Foundation

extension NSLocking {
/// Performs `body` with the lock held.
public func _performWithLock<Result>(
_ body: () throws -> Result
) rethrows -> Result {
self.lock()
defer { self.unlock() }
return try body()
}

/// Given that the lock is held, **unlocks it**, performs `body`,
/// then relocks it.
///
/// Be very careful with your thread-safety analysis when using this function!
public func _performWithoutLock<Result>(
_ body: () throws -> Result
) rethrows -> Result {
self.unlock()
defer { self.lock() }
return try body()
}
}
Loading

0 comments on commit e06fe31

Please sign in to comment.