-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add thread safety unit test for LazyCache #318
base: main
Are you sure you want to change the base?
Conversation
Add thread safety unit test for LazyCache
thanks @PetrGuan can you elaborate what this is testing? |
var bar: Int { return barCache.getValue(self) } | ||
var barCache = LazyCache<Foo, Int>(someExpensiveMethod) | ||
func someExpensiveMethod() -> Int { | ||
numCalls += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this thread safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think so. The someExpensiveMethod()
is protected by a lock. Maybe LazyCache
should be named something like ThreadSafeLazyCache
?
let foo = Foo() | ||
for _ in 0..<10 { | ||
dispatchGroup.enter() | ||
DispatchQueue.global().async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass the group to the queue method instead of manually enter/leave
Add thread safety unit test for LazyCache