removeValue and removeAll are async, which breaks the assumption of Dictionary
The implementation of removeValue and removeAll uses self.concurrentQueue.async, which results in a different behavior vs. the regular dictionary. This means it's not a fully drop-in replacement.
If a caller removes a value and then that caller (or a caller of the caller) checks the dictionary, it may still contain the value (for an indeterminate amount of time).
May I ask why these calls must be async? Thanks.
From my understanding, the barrier flag will prevent your concern. Checking the value will have to wait until the removal is done. Without the barrier flag, your concern would be correct.
In this code example the result of print is nil.
let tsDic = ThreadSafeDictionary<Int, String>()
tsDic[1] = "1"
tsDic[2] = "2"
tsDic.removeValue(forKey: 1)
print(tsDic[1])
If you remove the barrier flag then it would be "1".
But you are correct in that removeValue should return the value.