-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
307 additions
and
296 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
Sources/Merge/Intermodular/Extensions/Foundation/NSLocking++.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.