Skip to content

Commit

Permalink
Ensure proper loop label
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniomika committed Oct 2, 2024
1 parent a220a01 commit 3ff0e57
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ func (b *BaseConnector) Connect(client *Client, channels []*Channel) (error, err
for _, channel := range channels {
dataChannel := b.ensureChannel(channel)
dataChannel.Clients.Store(client.ID, client)
client.Channels.Store(dataChannel.ID, dataChannel)
defer func() {
client.Cleanup()
client.Channels.Delete(channel.ID)
dataChannel.Clients.Delete(client.ID)

client.Cleanup()

count := 0
for _, cl := range dataChannel.GetClients() {
if cl.Direction == ChannelDirectionInput || cl.Direction == ChannelDirectionInputOutput {
Expand All @@ -75,7 +78,6 @@ func (b *BaseConnector) Connect(client *Client, channels []*Channel) (error, err

b.Cleanup()
}()
client.Channels.Store(dataChannel.ID, dataChannel)
}

var (
Expand All @@ -101,6 +103,7 @@ func (b *BaseConnector) Connect(client *Client, channels []*Channel) (error, err
}

if client.BlockWrite {
mainLoop:
for {
count := 0
for _, channel := range client.GetChannels() {
Expand All @@ -112,14 +115,14 @@ func (b *BaseConnector) Connect(client *Client, channels []*Channel) (error, err
}

if count > 0 {
break
break mainLoop
}

select {
case <-client.Done:
break mainLoop
case <-time.After(1 * time.Millisecond):
continue
case <-client.Done:
break
}
}
}
Expand Down

0 comments on commit 3ff0e57

Please sign in to comment.