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() {
|
go func() {
|
||||||
ticker := time.NewTicker(screencastTimeout)
|
|
||||||
manager.logger.Debug().Msg("started emitting samples")
|
manager.logger.Debug().Msg("started emitting samples")
|
||||||
|
|
||||||
|
ticker := time.NewTicker(screencastTimeout)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-manager.emitStop:
|
case <-manager.emitStop:
|
||||||
manager.logger.Debug().Msg("stopped emitting samples")
|
manager.logger.Debug().Msg("stopped emitting samples")
|
||||||
ticker.Stop()
|
|
||||||
return
|
return
|
||||||
case <-manager.emitUpdate:
|
case <-manager.emitUpdate:
|
||||||
manager.logger.Debug().Msg("update emitting samples")
|
manager.logger.Debug().Msg("update emitting samples")
|
||||||
|
@ -18,7 +18,6 @@ var mu = sync.Mutex{}
|
|||||||
|
|
||||||
type DesktopManagerCtx struct {
|
type DesktopManagerCtx struct {
|
||||||
logger zerolog.Logger
|
logger zerolog.Logger
|
||||||
cleanup *time.Ticker
|
|
||||||
shutdown chan bool
|
shutdown chan bool
|
||||||
emmiter events.EventEmmiter
|
emmiter events.EventEmmiter
|
||||||
config *config.Desktop
|
config *config.Desktop
|
||||||
@ -27,7 +26,6 @@ type DesktopManagerCtx struct {
|
|||||||
func New(config *config.Desktop) *DesktopManagerCtx {
|
func New(config *config.Desktop) *DesktopManagerCtx {
|
||||||
return &DesktopManagerCtx{
|
return &DesktopManagerCtx{
|
||||||
logger: log.With().Str("module", "desktop").Logger(),
|
logger: log.With().Str("module", "desktop").Logger(),
|
||||||
cleanup: time.NewTicker(1 * time.Second),
|
|
||||||
shutdown: make(chan bool),
|
shutdown: make(chan bool),
|
||||||
emmiter: events.New(),
|
emmiter: events.New(),
|
||||||
config: config,
|
config: config,
|
||||||
@ -64,16 +62,15 @@ func (manager *DesktopManagerCtx) Start() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
ticker := time.NewTicker(1 * time.Second)
|
||||||
xorg.DisplayClose()
|
defer ticker.Stop()
|
||||||
manager.logger.Info().Msg("shutdown")
|
|
||||||
}()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-manager.shutdown:
|
case <-manager.shutdown:
|
||||||
|
xorg.DisplayClose()
|
||||||
return
|
return
|
||||||
case <-manager.cleanup.C:
|
case <-ticker.C:
|
||||||
xorg.CheckKeys(time.Second * 10)
|
xorg.CheckKeys(time.Second * 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +92,6 @@ func (manager *DesktopManagerCtx) OnAfterScreenSizeChange(listener func()) {
|
|||||||
func (manager *DesktopManagerCtx) Shutdown() error {
|
func (manager *DesktopManagerCtx) Shutdown() error {
|
||||||
manager.logger.Info().Msgf("desktop shutting down")
|
manager.logger.Info().Msgf("desktop shutting down")
|
||||||
|
|
||||||
manager.cleanup.Stop()
|
|
||||||
manager.shutdown <- true
|
manager.shutdown <- true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user