uidriver/mobile: Refactoring

This commit is contained in:
Hajime Hoshi 2020-08-31 01:01:36 +09:00
parent 8c779447db
commit f332fa61c1

View File

@ -17,7 +17,6 @@
package mobile package mobile
import ( import (
"context"
"fmt" "fmt"
"runtime" "runtime"
"runtime/debug" "runtime/debug"
@ -89,14 +88,13 @@ func (u *UserInterface) Update() error {
panic("mobile: glWorker must be initialized but not") panic("mobile: glWorker must be initialized but not")
} }
ctx, cancel := context.WithCancel(context.Background()) done := make(chan struct{})
go func() { go func() {
<-renderEndCh <-renderEndCh
cancel() close(done)
}() }()
workAvailable := u.glWorker.WorkAvailable() workAvailable := u.glWorker.WorkAvailable()
loop:
for { for {
select { select {
case <-workAvailable: case <-workAvailable:
@ -106,12 +104,11 @@ func (u *UserInterface) Update() error {
// Apprently there is an issue in the usage of Worker in gomobile or gomobile itself. // Apprently there is an issue in the usage of Worker in gomobile or gomobile itself.
// At least, freezing doesn't happen with this Gosched. // At least, freezing doesn't happen with this Gosched.
runtime.Gosched() runtime.Gosched()
case <-ctx.Done(): case <-done:
break loop
}
}
return nil return nil
} }
}
}
go func() { go func() {
<-renderEndCh <-renderEndCh