zntg/ui/queue.go

27 lines
345 B
Go
Raw Normal View History

2018-08-03 06:46:10 +00:00
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
}
}
}