(key string, newValue T, testFn func(T, bool) bool)
| 53 | } |
| 54 | |
| 55 | func (sm *SyncMap[T]) TestAndSet(key string, newValue T, testFn func(T, bool) bool) bool { |
| 56 | sm.lock.Lock() |
| 57 | defer sm.lock.Unlock() |
| 58 | currentValue, exists := sm.m[key] |
| 59 | if testFn(currentValue, exists) { |
| 60 | sm.m[key] = newValue |
| 61 | return true |
| 62 | } |
| 63 | return false |
| 64 | } |
| 65 | |
| 66 | func (sm *SyncMap[T]) GetOrCreate(key string, createFn func() T) T { |
| 67 | sm.lock.Lock() |
no outgoing calls
no test coverage detected