queue.go 402 B

123456789101112131415161718192021222324252627282930
  1. package binding
  2. import (
  3. "sync"
  4. "fyne.io/fyne/v2/internal/async"
  5. )
  6. var (
  7. once sync.Once
  8. queue *async.UnboundedFuncChan
  9. )
  10. func queueItem(f func()) {
  11. once.Do(func() {
  12. queue = async.NewUnboundedFuncChan()
  13. go func() {
  14. for f := range queue.Out() {
  15. f()
  16. }
  17. }()
  18. })
  19. queue.In() <- f
  20. }
  21. func waitForItems() {
  22. done := make(chan struct{})
  23. queue.In() <- func() { close(done) }
  24. <-done
  25. }