Skip to content

Instantly share code, notes, and snippets.

View einsteinx2's full-sized avatar

Ben Baron einsteinx2

View GitHub Profile
@einsteinx2
einsteinx2 / locking.swift
Last active March 2, 2019 17:25 — forked from kristopherjohnson/locking.swift
Simple synchronization functions for Swift, wrapping the Cocoa NSLocking classes
import Foundation
/// Protocol for NSLocking objects that also provide try()
public protocol TryLockable: NSLocking {
func `try`() -> Bool
}
// These Cocoa classes have tryLock()
extension NSLock: TryLockable {}
extension NSRecursiveLock: TryLockable {}