summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/uitask.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/redo/uitask.go b/redo/uitask.go
index 43068e7..c7faea2 100644
--- a/redo/uitask.go
+++ b/redo/uitask.go
@@ -15,20 +15,24 @@ func Go() error {
if err := uiinit(); err != nil {
return err
}
+ go uiissueloop()
uimsgloop()
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.
// It waits for f to execute before returning.
// Do cannot be called within event handlers or within Do itself.
func Do(f func()) {
done := make(chan struct{})
defer close(done)
- issue(func() {
+ issuer <- func() {
f()
done <- struct{}{}
- })
+ }
<-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.
// (TODO make sure this is the case for dialog boxes)
func Stop() {
- issue(uistop)
+ issuer <- uistop
+}
+
+func uiissueloop() {
+ for f := range issuer {
+ issue(f)
+ }
}
type event struct {