Added the new common uitask code to the redo.

This commit is contained in:
Pietro Gagliardi 2014-07-06 21:42:11 -04:00
parent 65a3c67ebd
commit fd183e8bf7
1 changed files with 40 additions and 0 deletions

40
redo/uitask.go Normal file
View File

@ -0,0 +1,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
}