Documentation ¶
Overview ¶
Package threadsafe implements data structures that are safe for use from multiple goroutines.
Index ¶
- type Map
- func (m *Map) Add(key, val interface{}) bool
- func (m *Map) Del(key interface{})
- func (m *Map) Do(f func(map[interface{}]interface{}))
- func (m *Map) Fetch(key, v interface{}) bool
- func (m *Map) Get(key interface{}) (val interface{}, ok bool)
- func (m *Map) Put(key, val interface{})
- func (m *Map) Update(key, v interface{}, fn func()) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
A Map is a map that is safe for concurrent access and updates. A Map must be created with NewMap.
func (*Map) Add ¶
Add stores a value in the map under key. If there is already a value in the map for key, Add does not replace it, and returns false.
func (*Map) Del ¶
func (m *Map) Del(key interface{})
Del deletes a value from a map. Subsequent Gets on the map will turn up empty.
func (*Map) Do ¶
func (m *Map) Do(f func(map[interface{}]interface{}))
Do calls f while holding the write lock for a Map.
func (*Map) Fetch ¶
Fetch stores the value corresponding with key in the Map into v. v must be a pointer to the value's type, or a run-time panic will occur. If the key is not present in the Map, v is untouched and Fetch returns false.
func (*Map) Get ¶
Get retrieves a value from the Map. If the value is not present, ok will be false.
func (*Map) Put ¶
func (m *Map) Put(key, val interface{})
Put stores a value in the map, overwriting any previous values stored under the key.
func (*Map) Update ¶
Update stores the Map value corresponding with key into v, and then calls fn. Once fn is returned, v is copied back into the Map under key. All other access to the Map is blocked until Update returns. If there is no value in the Map associated with key, fn is not called and Update returns false.
v must be a pointer to the same type as the item retrieved from the Map, or a run-time panic will occur.