mirror of
https://github.com/pointfreeco/swift-composable-architecture.git
synced 2025-12-20 09:11:33 +01:00
* Remove subscription on cancel * Slight refactor * Small refactor Subscription keeps strong reference of `CurrentValueRelay` similar to `CurrentValueSubject` * Add subscription lifetime tests * Use weak subscriptions and remove inside send * Change relay implementation * For loop better * Move tests to StoreTests.swift * A few more locks and a Shared test. --------- Co-authored-by: Brandon Williams <mbrandonw@hey.com>
28 lines
533 B
Swift
28 lines
533 B
Swift
import Foundation
|
|
|
|
extension UnsafeMutablePointer<os_unfair_lock_s> {
|
|
@inlinable @discardableResult
|
|
func sync<R>(_ work: () -> R) -> R {
|
|
os_unfair_lock_lock(self)
|
|
defer { os_unfair_lock_unlock(self) }
|
|
return work()
|
|
}
|
|
|
|
func lock() {
|
|
os_unfair_lock_lock(self)
|
|
}
|
|
|
|
func unlock() {
|
|
os_unfair_lock_unlock(self)
|
|
}
|
|
}
|
|
|
|
extension NSRecursiveLock {
|
|
@inlinable @discardableResult
|
|
@_spi(Internals) public func sync<R>(work: () -> R) -> R {
|
|
self.lock()
|
|
defer { self.unlock() }
|
|
return work()
|
|
}
|
|
}
|