Skip to content

Commit

Permalink
use a local variable
Browse files Browse the repository at this point in the history
  • Loading branch information
boks1971 committed Nov 20, 2023
1 parent 9a727bc commit 0acef17
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions signalclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *SignalClient) Start() {
return
}
c.readerClosedCh = make(chan struct{})
go c.readWorker()
go c.readWorker(c.readerClosedCh)
}

func (c *SignalClient) IsStarted() bool {
Expand Down Expand Up @@ -174,12 +174,13 @@ func (c *SignalClient) Join(urlPrefix string, token string, params *ConnectParam

func (c *SignalClient) Close() {
isStarted := c.IsStarted()
readerClosedCh := c.readerClosedCh
conn := c.websocketConn()
if conn != nil {
_ = conn.Close()
}
if isStarted {
<-c.readerClosedCh
<-readerClosedCh
}
}

Expand Down Expand Up @@ -344,11 +345,11 @@ func (c *SignalClient) handleResponse(res *livekit.SignalResponse) {
}
}

func (c *SignalClient) readWorker() {
func (c *SignalClient) readWorker(readerClosedCh chan struct{}) {
defer func() {
c.isStarted.Store(false)
c.conn.Store(nil)
close(c.readerClosedCh)
close(readerClosedCh)

if c.OnClose != nil {
c.OnClose()
Expand Down

0 comments on commit 0acef17

Please sign in to comment.