package main type SyncedPool struct { local *GrainLocalPool remotes []*RemoteGrainPool remoteIndex map[CartId]*RemoteGrainPool } func NewSyncedPool(local *GrainLocalPool) *SyncedPool { return &SyncedPool{ local: local, remotes: make([]*RemoteGrainPool, 0), remoteIndex: make(map[CartId]*RemoteGrainPool), } } func (p *SyncedPool) AddRemote(remote *RemoteGrainPool) { p.remotes = append(p.remotes, remote) // get all available grains from remote, and start syncing } func (p *SyncedPool) Process(id CartId, messages ...Message) ([]byte, error) { // check if local grain exists _, ok := p.local.grains[id] if !ok { // check if remote grain exists remoteGrain, ok := p.remoteIndex[id] if ok { return remoteGrain.Process(id, messages...) } } return p.local.Process(id, messages...) } func (p *SyncedPool) Get(id CartId) ([]byte, error) { // check if local grain exists _, ok := p.local.grains[id] if !ok { // check if remote grain exists remoteGrain, ok := p.remoteIndex[id] if ok { return remoteGrain.Get(id) } } return p.local.Get(id) }