Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created January 27, 2024 16:57
Show Gist options
  • Save laevandus/5595f216a92f16c5b283676f3efdbaed to your computer and use it in GitHub Desktop.
Save laevandus/5595f216a92f16c5b283676f3efdbaed to your computer and use it in GitHub Desktop.
final class Storage {
private let queue = DispatchQueue(label: "myexample", attributes: .concurrent)
private var _contents = [String: Data]()
private var contents: [String: Data] {
get {
queue.sync { _contents }
}
set {
queue.async(flags: .barrier) { self._contents = newValue }
}
}
func store(_ data: Data, forIdentifier id: String) {
contents[id] = data
}
// …
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment