1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Add ability to explicitly stop modules via a QuitChan

This commit is contained in:
Chris Cummer
2019-07-27 07:25:55 -07:00
parent cfd3c731ba
commit 73391b06e4
8 changed files with 50 additions and 19 deletions

View File

@@ -17,21 +17,22 @@ func Schedule(widget wtf.Wtfable) {
return
}
tick := time.NewTicker(interval)
quit := make(chan struct{})
timer := time.NewTicker(interval)
for {
select {
case <-tick.C:
case <-timer.C:
if widget.Enabled() {
widget.Refresh()
} else {
tick.Stop()
timer.Stop()
return
}
case quit := <-widget.QuitChan():
if quit == true {
timer.Stop()
return
}
case <-quit:
tick.Stop()
return
}
}
}

View File

@@ -60,14 +60,14 @@ func (wtfApp *WtfApp) Start() {
// Stop kills all the currently-running widgets in this app
func (wtfApp *WtfApp) Stop() {
wtfApp.disableAllWidgets()
wtfApp.stopAllWidgets()
}
/* -------------------- Unexported Functions -------------------- */
func (wtfApp *WtfApp) disableAllWidgets() {
func (wtfApp *WtfApp) stopAllWidgets() {
for _, widget := range wtfApp.Widgets {
widget.Disable()
widget.Stop()
}
}