Thread-safe access to online flag

This commit is contained in:
Bohdan Horbeshko 2026-08-06 13:17:58 -04:00
parent a117e1e3cb
commit 4e932d1e26
3 changed files with 6 additions and 5 deletions

View file

@ -5,6 +5,7 @@ import (
"path/filepath"
"strconv"
"sync"
"sync/atomic"
"time"
"dev.narayana.im/narayana/telegabber/calls/audio/ntgadapter"
@ -133,7 +134,7 @@ type Client struct {
resources map[string]bool
content *config.TelegramContentConfig
cache *cache.Cache
online bool
online atomic.Bool
loginWizard *loginWizardMetadata
loginStage LoginStage

View file

@ -397,7 +397,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) (strin
c.Session.Login = ""
c.wizardStageOrPrompt(LoginStageCancel, "")
c.online = false
c.online.Store(false)
// cleanup
case "cleanup":
c.unsubscribeFromAll()

View file

@ -158,7 +158,7 @@ func (c *Client) Connect(resource string, wasSessionLoginEmpty bool) error {
go c.updateHandler()
log.Warn("Going online")
c.online = true
c.online.Store(true)
c.locks.authorizationReady.Unlock()
c.addResource(resource)
@ -327,7 +327,7 @@ func (c *Client) forceClose() {
defer c.locks.authorizerReadLock.Unlock()
defer c.locks.authorizerWriteLock.Unlock()
c.online = false
c.online.Store(false)
c.authorizer = nil
}
@ -375,5 +375,5 @@ func (c *Client) cancelAuth() {
// Online checks if the updates listener is alive
func (c *Client) Online() bool {
return c.online
return c.online.Load()
}