MCPcopy
hub / github.com/wavetermdev/waveterm / TestAndSet

Method TestAndSet

pkg/util/ds/syncmap.go:55–64  ·  view source on GitHub ↗
(key string, newValue T, testFn func(T, bool) bool)

Source from the content-addressed store, hash-verified

53}
54
55func (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
66func (sm *SyncMap[T]) GetOrCreate(key string, createFn func() T) T {
67 sm.lock.Lock()

Callers 3

HandleCmdJobExitedFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected