type concurrentChecks struct { mutex sync.Mutex activeChecks map[string]int}
// addCheck waits until the processing for an item with the same token is finishedfunc (c *concurrentChecks) addCheck(token string) { for { c.mutex.Lock() if _, ok := c.activeChecks[token]; !ok { c.activeChecks[token] = 1 c.mutex.Unlock() return } c.mutex.Unlock() time.Sleep(20 * time.Millisecond) }}
func (c *concurrentChecks) removeCheck(token string) { c.mutex.Lock() defer c.mutex.Unlock() delete(c.activeChecks, token)}const concurrency = 48
type concurrentChecks struct {
mutex [concurrency]sync.Mutex
}
func (c *concurrentChecks) addCheck(token string) {
mutex_num := crc32.ChecksumIEEE([]byte(token)) % concurrency
c.mutex[mutex_num].Lock()
}
func (c *concurrentChecks) removeCheck(token string) {
mutex_num := crc32.ChecksumIEEE([]byte(token)) % concurrency
c.mutex[mutex_num].Unlock()
}