Package threadsafe implements data structures that are safe for use from multiple goroutines.



This section is empty.


This section is empty.


This section is empty.


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 NewMap

func NewMap() *Map

func (*Map) Add

func (m *Map) Add(key, val interface{}) bool

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

func (m *Map) Fetch(key, v interface{}) bool

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

func (m *Map) Get(key interface{}) (val interface{}, ok bool)

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

func (m *Map) Update(key, v interface{}, fn func()) bool

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.

Source Files