1
0
mirror of https://github.com/rivo/tview.git synced 2025-04-24 13:48:56 +08:00

TextView changed function is always called in a separate goroutine to avoid deadlocks. Fixes #416

This commit is contained in:
Oliver 2020-04-04 22:46:04 +02:00
parent cce7c98823
commit ca37f83cb2

View File

@ -329,7 +329,7 @@ func (t *TextView) SetRegions(regions bool) *TextView {
// - You can call Application.Draw() from this handler. // - You can call Application.Draw() from this handler.
// - You can call TextView.HasFocus() from this handler. // - You can call TextView.HasFocus() from this handler.
// - During the execution of this handler, access to any other variables from // - During the execution of this handler, access to any other variables from
// this primitive or any other primitive should be queued using // this primitive or any other primitive must be queued using
// Application.QueueUpdate(). // Application.QueueUpdate().
// //
// See package description for details on dealing with concurrency. // See package description for details on dealing with concurrency.
@ -607,7 +607,11 @@ func (t *TextView) Write(p []byte) (n int, err error) {
changed := t.changed changed := t.changed
t.Unlock() t.Unlock()
if changed != nil { if changed != nil {
defer changed() // Deadlocks may occur if we lock here. defer func() {
// We always call the "changed" function in a separate goroutine to avoid
// deadlocks.
go changed()
}()
} }
t.Lock() t.Lock()