-
-
Save laevandus/5595f216a92f16c5b283676f3efdbaed to your computer and use it in GitHub Desktop.
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
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