Skip to content

Instantly share code, notes, and snippets.

let dictLock = DispatchSemaphore(value: 1)
var originSemaphores: [String: DispatchSemaphore] = [:]
// make a non blocking HTTP request
func makeHttpRequest(url: String, origin: String, complete: @escaping (() -> Void)) {
dictLock.wait()
if originSemaphores[origin] == nil {
originSemaphores[origin] = DispatchSemaphore(value: 2)
}
let semaphore = originSemaphores[origin]!