3 ms·
There’s probably more but the singular best use-case I’ve found for embedding a struct is when you want a mutex. That is elegant. This example looks nice, but
by ljm 7y ago
There’s probably more but the singular best use-case I’ve found for embedding a struct is when you want a mutex.
That is elegant.
This example looks nice, but I think the naming of the structure and interfaces makes it hard to follow and a cache doesn’t necessarily benefit from it. In fact, it’s worse if your cache isn’t in-memory, and you’re not sharing an instance or a connection pool. If you are, this is just indirection and you can live with `Cache.get` just as well.
- sethammons 7y agoI'd recommend only embedding a mutex on private structs - you likely don't want to expose Lock and Unlock.