Skip to content

Instantly share code, notes, and snippets.

View gpambrozio's full-sized avatar

Gustavo Ambrozio gpambrozio

View GitHub Profile
@gpambrozio
gpambrozio / synchronized.swift
Created August 10, 2020 20:02
Synchronized in swift
func synchronized<T>(_ lock: Any, _ body: () throws -> T) rethrows -> T {
objc_sync_enter(lock)
defer { objc_sync_exit(lock) }
return try body()
}