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:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user