mirror of
https://github.com/jroimartin/gocui.git
synced 2025-04-26 13:48:49 +08:00
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++
|
ctr++
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
|
||||||
g.Execute(func(g *gocui.Gui) error {
|
g.Update(func(g *gocui.Gui) error {
|
||||||
v, err := g.View("ctr")
|
v, err := g.View("ctr")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
IMPORTANT: Views can only be created, destroyed or updated in three ways: from
|
||||||
the Layout function within managers, from keybinding callbacks or via
|
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
|
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")
|
v, err := g.View("viewname")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// handle error
|
// handle error
|
||||||
|
11
gui.go
11
gui.go
@ -303,11 +303,12 @@ type userEvent struct {
|
|||||||
f func(*Gui) error
|
f func(*Gui) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute executes the given function. This function can be called safely from
|
// Update executes the passed function. This method can be called safely from a
|
||||||
// a goroutine in order to update the GUI. It is important to note that it
|
// goroutine in order to update the GUI. It is important to note that the
|
||||||
// won't be executed immediately, instead it will be added to the user events
|
// passed function won't be executed immediately, instead it will be added to
|
||||||
// queue.
|
// the user events queue. Given that Update spawns a goroutine, the order in
|
||||||
func (g *Gui) Execute(f func(*Gui) error) {
|
// 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} }()
|
go func() { g.userEvents <- userEvent{f: f} }()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user