func GetEvents(sources []*EventSource) chan interface{} { ch := make(chan interface{}, 10) sourcesStopped := make(chan bool) for _, evSrc := range sources { go func() { <-evSrc.stopped sourcesStopped <- true }() } go func() { var queue *C.ALLEGRO_EVENT_QUEUE queue = C.al_create_event_queue() defer C.al_destroy_event_queue(queue) for _, src := range sources { ptr := (*C.ALLEGRO_EVENT_SOURCE)(src.src) C.al_register_event_source(queue, ptr) } stopped := false for !stopped { var gotEv sync.Mutex var al_event C.ALLEGRO_EVENT gotEv.Lock() go func() { C.al_wait_for_event(queue, &al_event) gotEv.Unlock() }() go func() { <-sourcesStopped stopped = true gotEv.Unlock() }() gotEv.Lock() ev := toEv(al_event) if ev != nil { ch <- ev } } }() return ch }
// Destroys the event queue. func (self *EventQueue) Destroy() { if self.handle != nil { C.al_destroy_event_queue(self.handle) } self.handle = nil }
func (e *EventQueue) Destroy() { C.al_destroy_event_queue((*C.ALLEGRO_EVENT_QUEUE)(unsafe.Pointer(e))) }