You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created a simple app with a window having three texts. I want to call function PostFunc and set their text to something else. But I think PostFunc does not work because of following race condition.
app := &views.Application{}
app.SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorWhite).
Background(tcell.ColorBlack))
app.SetRootWidget(window)
app.Start()
// time.Sleep(1 * time.Second)
app.PostFunc(setContent)
if e := app.Wait(); e != nil {
fmt.Fprintln(os.Stderr, e.Error())
os.Exit(1)
app.Starts() starts run function in a go routine and creates a screen if some screen is not set.
During the time when called app.Start() called and new screen is not initialize. PostFunc would return saying screen is nil.
Following is PostFunc code:
// PostFunc posts a function to be executed in the context of the
// application's event loop. Functions that need to update displayed
// state, etc. can do this to avoid holding locks.
func (app *Application) PostFunc(fn func()) {
ev := &eventAppFunc{fn: fn}
ev.SetEventNow()
if scr := app.screen; scr != nil { // Code returns from here
go func() { scr.PostEventWait(ev) }()
}
}
The text was updated successfully, but these errors were encountered:
Viv1k
changed the title
PostFunc
app PostFunc is never called
May 18, 2019
Viv1k
changed the title
app PostFunc is never called
app PostFunc is not called because of screen being nil while calling PostFunc [race condition]
May 18, 2019
I created a simple app with a window having three texts. I want to call function PostFunc and set their text to something else. But I think PostFunc does not work because of following race condition.
app.Starts()
startsrun
function in a go routine and creates a screen if some screen is not set.During the time when called app.Start() called and new screen is not initialize.
PostFunc
would return sayingscreen is nil
.Following is
PostFunc
code:The text was updated successfully, but these errors were encountered: