File: state.go

package info (click to toggle)
golang-github-cenk-rpc2 0.0~git20160427.0.7ab76d2e88c7-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 104 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 413 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package rpc2

import "sync"

type State struct {
	store map[string]interface{}
	m     sync.RWMutex
}

func NewState() *State {
	return &State{store: make(map[string]interface{})}
}

func (s *State) Get(key string) (value interface{}, ok bool) {
	s.m.RLock()
	value, ok = s.store[key]
	s.m.RUnlock()
	return
}

func (s *State) Set(key string, value interface{}) {
	s.m.Lock()
	s.store[key] = value
	s.m.Unlock()
}