Created
June 2, 2020 04:07
-
-
Save aainaj/8bc2a136403ee97ab2ce1cb544719a26 to your computer and use it in GitHub Desktop.
Featured Topics Concurrent Access Failure
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
func testFeaturedTopics() { | |
let count = 200 | |
for index in 0..<count { | |
FeaturedTopics.shared[String(index)] = index | |
} | |
// The dispatch queue executes the submitted blocks in parallel and waits for all iterations to complete before returning | |
DispatchQueue.concurrentPerform(iterations: count) { (index) in | |
if let indexNumber = FeaturedTopics.shared[String(index)] as? Int { | |
print(indexNumber) | |
} | |
} | |
FeaturedTopics.shared.reset() | |
// Re-add the values concurrently | |
DispatchQueue.concurrentPerform(iterations: count) { (index) in | |
print("index \(index)") | |
FeaturedTopics.shared[String(index)] = index | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment