Files
go-cart-actor/synced-pool.go
matst80 82dcd7871c
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 27s
sticky sessions
2024-11-09 01:26:46 +01:00

47 lines
1.1 KiB
Go

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)
}