The code (and even similar using channels) is highly inefficient. You need to
understand the expected collision rate because if it’s low (expected) paying
the lock cost on every operation is wasteful. Better to partition the work
based on the token (hash N) and avoid the lock operations.
You c
Check out https://pkg.go.dev/golang.org/x/sync/singleflight !
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
To view th
Hi all,
while refactoring an old application I found this code:
type concurrentChecks struct {
mutexsync.Mutex
activeChecks map[string]int
}
// addCheck waits until the processing for an item with the same token is
finished
func (c *concurrentChecks) addCheck(token string) {
for {
c.mut