Swiftpack.co -  Package - GottaGetSwifty/SwiftySemaphore
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
GottaGetSwifty/SwiftySemaphore
Handle Semaphores in Swift with a Property Wrapper
.package(url: "https://github.com/GottaGetSwifty/SwiftySemaphore.git", from: "0.1.0")

SwiftySemaphore

Swift Package Manager Platforms Build Status

Easily add a Semaphore to Property Access

Rather than handling a semaphore manually, use a Property Wrapper to reduce boilerplate

Turn this boilerplate

class YourType {
    private let semaphore = DispatchSemaphore(value: 1)
    private var _count: Int
    
    func setCount(_ count: Int) {
        defer {
            semaphore.signal()
        }
        semaphore.wait()
        _count = count
    }
    
    func getCount() -> Int {
        defer {
            semaphore.signal()
        }
        semaphore.wait()
        return _count
    }
}

Into a basic type with controlled access!

class YourType {

    @Semaphore
    private var count: Int
}

GitHub

link
Stars: 0
Last commit: 3 weeks ago

Dependencies

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco