pull/739/head
Brendan Bosman 2 years ago
parent 8c43f7c856
commit b8be29df3e

@ -49,7 +49,7 @@ const (
// element after f has executed. // element after f has executed.
type queuedUpdate struct { type queuedUpdate struct {
f func() f func()
done chan struct{} //done chan struct{}
} }
// Application represents the top node of an application. // Application represents the top node of an application.
@ -142,9 +142,9 @@ func (a *Application) Close() error {
}() }()
// flush updates channel // flush updates channel
go func() { go func() {
for up := range a.updates { for range a.updates {
// important to set done for calling channel to be able to return // important to set done for calling channel to be able to return
up.done <- struct{}{} //up.done <- struct{}{}
} }
}() }()
@ -440,9 +440,9 @@ EventLoop:
break EventLoop break EventLoop
} }
update.f() update.f()
if update.done != nil { //if update.done != nil {
update.done <- struct{}{} // update.done <- struct{}{}
} //}
} }
} }
// call the runCancelFunc when exiting eventLoop. // call the runCancelFunc when exiting eventLoop.
@ -815,32 +815,43 @@ func (a *Application) GetFocus() Primitive {
// up with an immediate refresh of the screen. // up with an immediate refresh of the screen.
// //
// This function returns after f has executed. // This function returns after f has executed.
func (a *Application) QueueUpdate(f func()) *Application { func (a *Application) QueueUpdate(
f func(),
) *Application {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
// dealing with panic, as we can still get a closed channel // dealing with panic, as we can still get a closed channel
} }
}() }()
// check to see if the Application.Run is still valid // check to see if the Application.Run is still valid
ch := make(chan struct{}) //ch := make(chan struct{})
msg := queuedUpdate{ msg := queuedUpdate{
f: f, f: f,
done: ch, //done: ch,
} }
if a.runContext.Err() == nil { if a.runContext.Err() == nil {
a.updates <- msg select {
<-ch case a.updates <- msg:
break
default:
break
}
} }
return a return a
} }
// QueueUpdateDraw works like QueueUpdate() except it refreshes the screen // QueueUpdateDraw works like QueueUpdate() except it refreshes the screen
// immediately after executing f. // immediately after executing f.
func (a *Application) QueueUpdateDraw(f func()) *Application { func (a *Application) QueueUpdateDraw(
a.QueueUpdate(func() { f func(),
) *Application {
a.QueueUpdate(
func() {
f() f()
a.draw() a.draw()
}) },
)
return a return a
} }

Loading…
Cancel
Save