This commit is contained in:
@@ -5,10 +5,12 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RemoteGrainPool struct {
|
||||
mu sync.RWMutex
|
||||
Host string
|
||||
grains map[CartId]RemoteGrain
|
||||
}
|
||||
@@ -87,7 +89,9 @@ func NewRemoteGrainPool(addr string) *RemoteGrainPool {
|
||||
}
|
||||
|
||||
func (p *RemoteGrainPool) findRemoteGrain(id CartId) *RemoteGrain {
|
||||
p.mu.RLock()
|
||||
grain, ok := p.grains[id]
|
||||
p.mu.RUnlock()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
@@ -99,7 +103,9 @@ func (p *RemoteGrainPool) findOrCreateGrain(id CartId) *RemoteGrain {
|
||||
grain := p.findRemoteGrain(id)
|
||||
if grain == nil {
|
||||
grain = NewRemoteGrain(id, p.Host)
|
||||
p.mu.Lock()
|
||||
p.grains[id] = *grain
|
||||
p.mu.Unlock()
|
||||
grain.Connect()
|
||||
}
|
||||
return grain
|
||||
|
||||
Reference in New Issue
Block a user