Skip to content

Instantly share code, notes, and snippets.

@isaac-weisberg
Created November 5, 2019 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaac-weisberg/901a28c317d624677fb753a787f89c06 to your computer and use it in GitHub Desktop.
Save isaac-weisberg/901a28c317d624677fb753a787f89c06 to your computer and use it in GitHub Desktop.
class Qutex<Value> {
var value: Value
init(value: Value) {
self.value = value
}
let queue = DispatchQueue(label: "net.caroline-weisberg.qutex",
attributes: [.concurrent])
func read() -> Value {
queue.sync {
value
}
}
func mutate(_ actions: (inout Value) -> Void) {
queue.sync(flags: .barrier) {
actions(&value)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment