Swiftpack.co - GottaGetSwifty/SwiftySemaphore as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by GottaGetSwifty.
GottaGetSwifty/SwiftySemaphore 0.1.0
Handle Semaphores in Swift with a Property Wrapper
⭐️ 1
🕓 3 years ago
.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: 1
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

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