pool.go 505 B

1234567891011121314151617181920212223242526272829303132
  1. package widget
  2. import (
  3. "sync"
  4. "fyne.io/fyne/v2"
  5. )
  6. type pool interface {
  7. Obtain() fyne.CanvasObject
  8. Release(fyne.CanvasObject)
  9. }
  10. var _ pool = (*syncPool)(nil)
  11. type syncPool struct {
  12. sync.Pool
  13. }
  14. // Obtain returns an item from the pool for use
  15. func (p *syncPool) Obtain() (item fyne.CanvasObject) {
  16. o := p.Get()
  17. if o != nil {
  18. item = o.(fyne.CanvasObject)
  19. }
  20. return
  21. }
  22. // Release adds an item into the pool to be used later
  23. func (p *syncPool) Release(item fyne.CanvasObject) {
  24. p.Put(item)
  25. }