Skip to content

Instantly share code, notes, and snippets.

@pwightman
Created February 6, 2015 00:30
Show Gist options
  • Save pwightman/43cce849f7152842f03c to your computer and use it in GitHub Desktop.
Save pwightman/43cce849f7152842f03c to your computer and use it in GitHub Desktop.
class Locks {
private var queuedDocuments = [String:Document]()
private var inFlightDocuments = [String:Document]()
private let queuedQueue = dispatch_queue_create("com.lucidchart.DocumentStateStoreLocks.queued", DISPATCH_QUEUE_SERIAL)
private let inFlightQueue = dispatch_queue_create("com.lucidchart.DocumentStateStoreLocks.inFlight", DISPATCH_QUEUE_SERIAL)
func queued(block: [String:Document] -> [String:Document]) {
dispatch_sync(queuedQueue) {
self.queuedDocuments = block(self.queuedDocuments)
}
}
func inFlight(block: [String:Document] -> [String:Document]) {
dispatch_sync(inFlightQueue) {
self.inFlightDocuments = block(self.inFlightDocuments)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment