diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-11 21:57:20 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-11 21:57:20 -0400 |
| commit | eb504480b192763ca62d15fa1d693c1a7afd6914 (patch) | |
| tree | 98ba73d4cb8a27b6aac8df90e83b7038429281cc /redo/uitask.go | |
| parent | 166eaeb7db48232cfac460d8d6d8d8476e7a8664 (diff) | |
Fixed the weird crash with calling Do() recursively; woo!
Diffstat (limited to 'redo/uitask.go')
| -rw-r--r-- | redo/uitask.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/redo/uitask.go b/redo/uitask.go index c7faea2..f9b9fc4 100644 --- a/redo/uitask.go +++ b/redo/uitask.go @@ -21,7 +21,8 @@ func Go() error { } // 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()) +// Notice that this is a pointer ot a function. See Do() below for details. +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. @@ -29,10 +30,14 @@ var issuer = make(chan func()) func Do(f func()) { done := make(chan struct{}) defer close(done) - issuer <- func() { + // THIS MUST BE A POINTER. + // Previously, the pointer was constructed within issue(). + // This meant that if the Do() was stalled, the garbage collector came in and reused the pointer value too soon! + call := func() { f() done <- struct{}{} } + issuer <- &call <-done } @@ -42,7 +47,10 @@ 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() { - issuer <- uistop + // can't send this directly across issuer + go func() { + Do(uistop) + }() } func uiissueloop() { |
