Last active
April 15, 2022 04:56
-
-
Save Nirajpaul2/1334756a700ab9c071b95cea70b6f4d4 to your computer and use it in GitHub Desktop.
AtomicWrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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