mirror of https://github.com/jroimartin/gocui.git
Rename *Gui.Execute() to *Gui.Update()
This commit is contained in:
parent
75a7ad2750
commit
6564cfcacb
|
@ -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
|
||||
|
|
6
doc.go
6
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
|
||||
|
|
11
gui.go
11
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} }()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue