mirror of https://github.com/liamg/aminal.git
Change waiting for `gui.waker()` function so that now it uses `sync.WaitGroup` instead of a channel
This commit is contained in:
parent
29e2f6861a
commit
d65f22c819
14
gui/gui.go
14
gui/gui.go
|
@ -67,7 +67,6 @@ type GUI struct {
|
||||||
selectionRegionMode buffer.SelectionRegionMode
|
selectionRegionMode buffer.SelectionRegionMode
|
||||||
|
|
||||||
mainThreadFunc chan func()
|
mainThreadFunc chan func()
|
||||||
wakerEnded chan bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Min(x, y int) int {
|
func Min(x, y int) int {
|
||||||
|
@ -335,7 +334,6 @@ func (gui *GUI) Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *GUI) Render() error {
|
func (gui *GUI) Render() error {
|
||||||
|
|
||||||
gui.logger.Debugf("Creating window...")
|
gui.logger.Debugf("Creating window...")
|
||||||
var err error
|
var err error
|
||||||
gui.window, err = gui.createWindow()
|
gui.window, err = gui.createWindow()
|
||||||
|
@ -429,7 +427,9 @@ func (gui *GUI) Render() error {
|
||||||
showMessage := true
|
showMessage := true
|
||||||
|
|
||||||
stop := make(chan struct{})
|
stop := make(chan struct{})
|
||||||
go gui.waker(stop)
|
var waitForWaker sync.WaitGroup
|
||||||
|
waitForWaker.Add(1)
|
||||||
|
go gui.waker(stop, &waitForWaker)
|
||||||
|
|
||||||
for !gui.window.ShouldClose() {
|
for !gui.window.ShouldClose() {
|
||||||
gui.redraw(true)
|
gui.redraw(true)
|
||||||
|
@ -496,7 +496,7 @@ Buffer Size: %d lines
|
||||||
gui.logger.Debug("Stopping render...")
|
gui.logger.Debug("Stopping render...")
|
||||||
|
|
||||||
close(stop) // Tell waker to end...
|
close(stop) // Tell waker to end...
|
||||||
<-gui.wakerEnded // ...and wait it to end
|
waitForWaker.Wait() // ...and wait it to end
|
||||||
|
|
||||||
gui.logger.Debug("Render stopped")
|
gui.logger.Debug("Render stopped")
|
||||||
|
|
||||||
|
@ -508,8 +508,9 @@ Buffer Size: %d lines
|
||||||
// waking up the main thread when the GUI needs to be
|
// waking up the main thread when the GUI needs to be
|
||||||
// redrawn. Limiting is applied on wakeups to avoid excessive CPU
|
// redrawn. Limiting is applied on wakeups to avoid excessive CPU
|
||||||
// usage when the terminal is being updated rapidly.
|
// usage when the terminal is being updated rapidly.
|
||||||
func (gui *GUI) waker(stop <-chan struct{}) {
|
func (gui *GUI) waker(stop <-chan struct{}, wg *sync.WaitGroup) {
|
||||||
gui.wakerEnded = make(chan bool)
|
defer wg.Done()
|
||||||
|
|
||||||
dirty := gui.terminal.Dirty()
|
dirty := gui.terminal.Dirty()
|
||||||
var nextWake <-chan time.Time
|
var nextWake <-chan time.Time
|
||||||
var last time.Time
|
var last time.Time
|
||||||
|
@ -540,7 +541,6 @@ forLoop:
|
||||||
break forLoop
|
break forLoop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gui.wakerEnded <- true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *GUI) renderTerminalData(shouldLock bool) {
|
func (gui *GUI) renderTerminalData(shouldLock bool) {
|
||||||
|
|
Loading…
Reference in New Issue