adam-gui/vendor/fyne.io/fyne/v2/widget/pool.go

33 lines
505 B
Go
Raw Normal View History

2024-04-29 19:13:50 +02:00
package widget
import (
"sync"
"fyne.io/fyne/v2"
)
type pool interface {
Obtain() fyne.CanvasObject
Release(fyne.CanvasObject)
}
var _ pool = (*syncPool)(nil)
type syncPool struct {
sync.Pool
}
// Obtain returns an item from the pool for use
func (p *syncPool) Obtain() (item fyne.CanvasObject) {
o := p.Get()
if o != nil {
item = o.(fyne.CanvasObject)
}
return
}
// Release adds an item into the pool to be used later
func (p *syncPool) Release(item fyne.CanvasObject) {
p.Put(item)
}