Skip to content

Instantly share code, notes, and snippets.

@Nirajpaul2
Last active April 15, 2022 04:56
Show Gist options
  • Save Nirajpaul2/1334756a700ab9c071b95cea70b6f4d4 to your computer and use it in GitHub Desktop.
Save Nirajpaul2/1334756a700ab9c071b95cea70b6f4d4 to your computer and use it in GitHub Desktop.
AtomicWrapper
struct Atomic<Value> {
private let queue = DispatchQueue(label: "com.vadimbulavin.atomic")
private var value: Value
init(wrappedValue: Value) {
self.value = wrappedValue
}
var wrappedValue: Value {
get {
return queue.sync { value }
}
set {
queue.sync { value = newValue }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment