Skip to content

Commit

Permalink
Multiclient reconnect will also trigger onConnect event
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Jan 24, 2024
1 parent b309bdf commit c024536
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions multiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,26 @@ func NewMultiClient(account *Account, baseIdentifier string, numSubClients int,

wg.Done()

node, ok := <-client.OnConnect.C
if !ok {
return
}
go func() {
for {
select {
case node, ok := <-client.OnConnect.C:
if !ok {
return
}

m.lock.RLock()
if m.isClosed {
m.lock.RUnlock()
return
}
m.OnConnect.receive(node)
m.lock.RUnlock()
m.lock.RLock()
if m.isClosed {
m.lock.RUnlock()
return
}
m.OnConnect.receive(node)
m.lock.RUnlock()
case <-m.onClose:
return
}
}
}()

for {
select {
Expand Down

0 comments on commit c024536

Please sign in to comment.