aboutsummaryrefslogtreecommitdiffstats
path: root/mux.go
diff options
context:
space:
mode:
authorfaiface <faiface2202@gmail.com>2019-05-03 18:00:13 +0200
committerfaiface <faiface2202@gmail.com>2019-05-03 18:00:13 +0200
commitaa77e994262bd4c5cd6857d6d1e7305b72e05bbb (patch)
treeb5397850c6dc312dd4497d75e1ddcc8d78460862 /mux.go
parentda46bd5f9051999c1e7e6ef723e049cb4f666ab9 (diff)
downloadgui-aa77e994262bd4c5cd6857d6d1e7305b72e05bbb.zip
mux: fix a bug and document it very well
Diffstat (limited to 'mux.go')
-rw-r--r--mux.go27
1 files changed, 24 insertions, 3 deletions
diff --git a/mux.go b/mux.go
index 7b051cb..1ee43bf 100644
--- a/mux.go
+++ b/mux.go
@@ -64,9 +64,30 @@ func (mux *Mux) makeEnv(master bool) Env {
mux.mu.Unlock()
go func() {
- for d := range drawChan {
- mux.draw <- d
- }
+ func() {
+ // When the master Env gets its Draw() channel closed, it closes all the Events()
+ // channels of all the children Envs, and it also closes the internal draw channel
+ // of the Mux. Otherwise, closing the Draw() channel of the master Env wouldn't
+ // close the Env the Mux is muxing. However, some child Envs of the Mux may still
+ // send some drawing commmands before they realize that their Events() channel got
+ // closed.
+ //
+ // That is perfectly fine if their drawing commands simply get ignored. This down here
+ // is a little hacky, but (I hope) perfectly fine solution to the problem.
+ //
+ // When the internal draw channel of the Mux gets closed, the line marked with ! will
+ // cause panic. We recover this panic, then we receive, but ignore all furhter draw
+ // commands, correctly draining the Env until it closes itself.
+ defer func() {
+ if recover() != nil {
+ for range drawChan {
+ }
+ }
+ }()
+ for d := range drawChan {
+ mux.draw <- d // !
+ }
+ }()
if master {
mux.mu.Lock()
for _, eventsIn := range mux.eventsIns {