more customer
This commit is contained in:
@@ -43,6 +43,9 @@ type GrainPoolConfig[V any] struct {
|
||||
Hostname string
|
||||
Spawn func(ctx context.Context, id uint64) (Grain[V], error)
|
||||
SpawnHost func(host string) (Host[V], error)
|
||||
// Destroy is an optional cleanup hook called when a grain is evicted on TTL
|
||||
// (e.g. to detach inventory subscriptions wired into its mutations). Leave
|
||||
// nil when there is nothing to clean up — purge() skips a nil Destroy.
|
||||
Destroy func(grain Grain[V]) error
|
||||
TTL time.Duration
|
||||
PoolSize int
|
||||
@@ -96,8 +99,10 @@ func (p *SimpleGrainPool[V]) purge() {
|
||||
for id, grain := range p.grains {
|
||||
if grain.GetLastAccess().Before(purgeLimit) {
|
||||
purgedIds = append(purgedIds, id)
|
||||
if err := p.destroy(grain); err != nil {
|
||||
log.Printf("failed to destroy grain %d: %v", id, err)
|
||||
if p.destroy != nil {
|
||||
if err := p.destroy(grain); err != nil {
|
||||
log.Printf("failed to destroy grain %d: %v", id, err)
|
||||
}
|
||||
}
|
||||
|
||||
delete(p.grains, id)
|
||||
|
||||
Reference in New Issue
Block a user