mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
use defer for ticker.
This commit is contained in:
parent
bdff2ddabe
commit
01c0f269ee
@ -40,14 +40,15 @@ func screencastNew(enabled bool, pipelineStr string) *ScreencastManagerCtx {
|
||||
}
|
||||
|
||||
go func() {
|
||||
ticker := time.NewTicker(screencastTimeout)
|
||||
manager.logger.Debug().Msg("started emitting samples")
|
||||
|
||||
ticker := time.NewTicker(screencastTimeout)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-manager.emitStop:
|
||||
manager.logger.Debug().Msg("stopped emitting samples")
|
||||
ticker.Stop()
|
||||
return
|
||||
case <-manager.emitUpdate:
|
||||
manager.logger.Debug().Msg("update emitting samples")
|
||||
|
@ -18,7 +18,6 @@ var mu = sync.Mutex{}
|
||||
|
||||
type DesktopManagerCtx struct {
|
||||
logger zerolog.Logger
|
||||
cleanup *time.Ticker
|
||||
shutdown chan bool
|
||||
emmiter events.EventEmmiter
|
||||
config *config.Desktop
|
||||
@ -27,7 +26,6 @@ type DesktopManagerCtx struct {
|
||||
func New(config *config.Desktop) *DesktopManagerCtx {
|
||||
return &DesktopManagerCtx{
|
||||
logger: log.With().Str("module", "desktop").Logger(),
|
||||
cleanup: time.NewTicker(1 * time.Second),
|
||||
shutdown: make(chan bool),
|
||||
emmiter: events.New(),
|
||||
config: config,
|
||||
@ -64,16 +62,15 @@ func (manager *DesktopManagerCtx) Start() {
|
||||
})
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
xorg.DisplayClose()
|
||||
manager.logger.Info().Msg("shutdown")
|
||||
}()
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-manager.shutdown:
|
||||
xorg.DisplayClose()
|
||||
return
|
||||
case <-manager.cleanup.C:
|
||||
case <-ticker.C:
|
||||
xorg.CheckKeys(time.Second * 10)
|
||||
}
|
||||
}
|
||||
@ -95,7 +92,6 @@ func (manager *DesktopManagerCtx) OnAfterScreenSizeChange(listener func()) {
|
||||
func (manager *DesktopManagerCtx) Shutdown() error {
|
||||
manager.logger.Info().Msgf("desktop shutting down")
|
||||
|
||||
manager.cleanup.Stop()
|
||||
manager.shutdown <- true
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user