summaryrefslogtreecommitdiff
path: root/redo/uitask.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-07-08 00:29:43 -0400
committerPietro Gagliardi <[email protected]>2014-07-08 00:29:43 -0400
commitc40d950654efd84c8f81658ee6cb125e4d90e290 (patch)
treeee93ba24e421e69a65bfbb3e9543744e3eb0b63d /redo/uitask.go
parentd874148760328786c9d12f871a27b97be0774a6d (diff)
Made event handlers more robust.
Diffstat (limited to 'redo/uitask.go')
-rw-r--r--redo/uitask.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/redo/uitask.go b/redo/uitask.go
index 32f8faf..7231220 100644
--- a/redo/uitask.go
+++ b/redo/uitask.go
@@ -39,6 +39,7 @@ func uitask() {
var stall = make(chan struct{})
// This is the common code for running an event.
+// It runs on the main thread without a message pump; it provides its own.
// TODO
// - define event
// - figure out how to return values from event handlers
@@ -50,7 +51,26 @@ func doevent(e event) {
close(c)
}()
for req := range c {
- issue(req)
+ // note: this is perform, not issue!
+ // doevent runs on the main thread without a message pump!
+ perform(req)
}
- stall <- struct{}{} // leave event handler
+ // leave the event handler; leave it only after returning from an event handler so we must issue it like a normal Request
+ issue(&Request{
+ op: func() {
+ stall <- struct{}{}
+ },
+ // unfortunately, closing a nil channel causes a panic
+ // therefore, we have to make a dummy channel
+ // TODO add conditional checks to the request handler instead?
+ resp: make(chan interface{}),
+ })
+}
+
+// Common code for performing a Request.
+// This should run on the main thread.
+// Implementations of issue() should call this.
+func perform(req *Request) {
+ req.op()
+ close(req.resp)
}