MCPcopy Index your code
hub / github.com/aceld/zinx / GetOrSet

Method GetOrSet

zutils/shard_lock_map.go:180–185  ·  view source on GitHub ↗

GetOrSet gets the value for the given key, or sets it if it doesn't exist. Returns the value and whether it was set (true) or already existed (false).

(key string, value interface{})

Source from the content-addressed store, hash-verified

178// GetOrSet gets the value for the given key, or sets it if it doesn't exist.
179// Returns the value and whether it was set (true) or already existed (false).
180func (slm ShardLockMaps) GetOrSet(key string, value interface{}) (interface{}, bool) {
181 if v, ok := slm.Get(key); ok {
182 return v, false
183 }
184 return slm.doSetWithLockCheck(key, value)
185}
186
187// GetOrSetFunc gets the value for the given key, or sets it using the provided function if it doesn't exist.
188// The function f is called outside the lock to avoid deadlocks.

Callers 1

TestGetOrSetFunction · 0.95

Calls 2

GetMethod · 0.95
doSetWithLockCheckMethod · 0.95

Tested by 1

TestGetOrSetFunction · 0.76