diff --git a/_examples/goroutine.go b/_examples/goroutine.go index a2d7e3d..81c0835 100644 --- a/_examples/goroutine.go +++ b/_examples/goroutine.go @@ -83,7 +83,7 @@ func counter(g *gocui.Gui) { ctr++ mu.Unlock() - g.Execute(func(g *gocui.Gui) error { + g.Update(func(g *gocui.Gui) error { v, err := g.View("ctr") if err != nil { return err diff --git a/doc.go b/doc.go index 9022832..fe128af 100644 --- a/doc.go +++ b/doc.go @@ -70,11 +70,11 @@ Mouse events are handled like any other keybinding: IMPORTANT: Views can only be created, destroyed or updated in three ways: from the Layout function within managers, from keybinding callbacks or via -*Gui.Execute(). The reason for this is that it allows gocui to be +*Gui.Update(). The reason for this is that it allows gocui to be concurrent-safe. So, if you want to update your GUI from a goroutine, you must -use *Gui.Execute(). For example: +use *Gui.Update(). For example: - g.Execute(func(g *gocui.Gui) error { + g.Update(func(g *gocui.Gui) error { v, err := g.View("viewname") if err != nil { // handle error diff --git a/gui.go b/gui.go index 37b15fe..6be49bb 100644 --- a/gui.go +++ b/gui.go @@ -303,11 +303,12 @@ type userEvent struct { f func(*Gui) error } -// Execute executes the given function. This function can be called safely from -// a goroutine in order to update the GUI. It is important to note that it -// won't be executed immediately, instead it will be added to the user events -// queue. -func (g *Gui) Execute(f func(*Gui) error) { +// Update executes the passed function. This method can be called safely from a +// goroutine in order to update the GUI. It is important to note that the +// passed function won't be executed immediately, instead it will be added to +// the user events queue. Given that Update spawns a goroutine, the order in +// which the user events will be handled is not guaranteed. +func (g *Gui) Update(f func(*Gui) error) { go func() { g.userEvents <- userEvent{f: f} }() }