package ui type Queue struct { q chan func(Context) } func NewQueue() *Queue { return &Queue{make(chan func(Context), 4)} } func (q *Queue) Do(act func(Context)) { go func() { // Non-blocking queue q.q <- act }() } func (q *Queue) Process(ctx Context) { for { select { case act := <-q.q: act(ctx) default: return } } }