more stuff

This commit is contained in:
matst80
2024-11-09 01:02:17 +01:00
parent 356f5effba
commit c3d30ea0b3
12 changed files with 153 additions and 102 deletions

46
synced-pool.go Normal file
View File

@@ -0,0 +1,46 @@
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)
}