mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:22:22 +00:00
This commit is contained in:
parent
105da782d9
commit
caa0429d06
@ -96,8 +96,8 @@ func NewKVStoreService() *KVStoreService {
|
||||
|
||||
```go
|
||||
func (p *KVStoreService) Get(key string, value *string) error {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if v, ok := p.m[key]; ok {
|
||||
*value = v
|
||||
@ -108,8 +108,8 @@ func (p *KVStoreService) Get(key string, value *string) error {
|
||||
}
|
||||
|
||||
func (p *KVStoreService) Set(kv [2]string, reply *struct{}) error {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
key, value := kv[0], kv[1]
|
||||
|
||||
@ -133,9 +133,9 @@ func (p *KVStoreService) Watch(timeoutSecond int, keyChanged *string) error {
|
||||
id := fmt.Sprintf("watch-%s-%03d", time.Now(), rand.Int())
|
||||
ch := make(chan string, 10) // buffered
|
||||
|
||||
p.Lock()
|
||||
p.mu.Lock()
|
||||
p.filter[id] = func(key string) { ch <- key }
|
||||
p.Unlock()
|
||||
p.mu.Unlock()
|
||||
|
||||
select {
|
||||
case <-time.After(time.Duration(timeoutSecond) * time.Second):
|
||||
|
Loading…
x
Reference in New Issue
Block a user