Fixed issuing in the new system. Now to figure out why it stalls...

This commit is contained in:
Pietro Gagliardi 2014-07-19 10:10:52 -04:00
parent e73e7ab733
commit 627abfd593
1 changed files with 13 additions and 3 deletions

View File

@ -15,20 +15,24 @@ func Go() error {
if err := uiinit(); err != nil { if err := uiinit(); err != nil {
return err return err
} }
go uiissueloop()
uimsgloop() uimsgloop()
return nil return nil
} }
// To ensure that Do() and Stop() only do things after Go() has been called, this channel accepts the requests to issue. The issuing is done by uiissueloop() below.
var issuer = make(chan func())
// Do performs f on the main loop, as if it were an event handler. // Do performs f on the main loop, as if it were an event handler.
// It waits for f to execute before returning. // It waits for f to execute before returning.
// Do cannot be called within event handlers or within Do itself. // Do cannot be called within event handlers or within Do itself.
func Do(f func()) { func Do(f func()) {
done := make(chan struct{}) done := make(chan struct{})
defer close(done) defer close(done)
issue(func() { issuer <- func() {
f() f()
done <- struct{}{} done <- struct{}{}
}) }
<-done <-done
} }
@ -38,7 +42,13 @@ func Do(f func()) {
// Stop will not have an effect until any event handlers or dialog boxes presently active return. // Stop will not have an effect until any event handlers or dialog boxes presently active return.
// (TODO make sure this is the case for dialog boxes) // (TODO make sure this is the case for dialog boxes)
func Stop() { func Stop() {
issue(uistop) issuer <- uistop
}
func uiissueloop() {
for f := range issuer {
issue(f)
}
} }
type event struct { type event struct {