blob: c29470a361493ca2d6d49c0d6cc04ccd31fe8095 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// 6 july 2014
package ui
// TODO Go, Start, Stop
// This is the ui main loop.
// It is spawned by Go as a goroutine.
func uitask() {
for {
select {
case req := <-Do:
// TODO foreign event
issue(req)
case <-stall: // wait for event to finish
<-stall // see below for information
}
}
}
// At each event, this is pulsed twice: once when the event begins, and once when the event ends.
// Do is not processed in between.
var stall = make(chan struct{})
// This is the common code for running an event.
// TODO
// - define event
// - figure out how to return values from event handlers
func doevent(e event) {
stall <- struct{}{} // enter event handler
c := make(Doer)
go func() {
e.do(c)
close(c)
}()
for req := range c {
issue(req)
}
stall <- struct{}{} // leave event handler
}
|