Skip to content

Commit

Permalink
refactor: move wg to partybase
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Jan 5, 2024
1 parent f4db639 commit 9f6cd07
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ type client struct {
lastID int64
backoffFactory func() backoff.BackOff
cancelFunc context.CancelFunc
wg sync.WaitGroup
}

func (c *client) Start() {
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ var _ = Describe("Client", func() {
panicableInfo.shouldPanic.Store(true)
panicableDebug.shouldPanic.Store(true)
// Ensure that we really don't get any logs anymore
time.Sleep(1 * time.Second)
time.Sleep(500 * time.Millisecond)
Expect(clientConn.State()).To(BeEquivalentTo(ClientClosed))
server.cancel()
close(done)
Expand Down
3 changes: 3 additions & 0 deletions loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func (l *loop) Run(connected chan struct{}) (err error) {
close(connected)
// Process messages
ch := make(chan receiveResult, 1)
wg := l.party.waitGroup()
wg.Add(1)
go func() {
defer wg.Done()
recv := l.hubConn.Receive()
loop:
for {
Expand Down
20 changes: 14 additions & 6 deletions party.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package signalr

import (
"context"
"sync"
"time"

"github.com/go-kit/log"
Expand Down Expand Up @@ -29,7 +30,7 @@ type Party interface {
insecureSkipVerify() bool
setInsecureSkipVerify(skip bool)

originPatterns() [] string
originPatterns() []string
setOriginPatterns(orgs []string)

chanReceiveTimeout() time.Duration
Expand All @@ -50,6 +51,8 @@ type Party interface {

maximumReceiveMessageSize() uint
setMaximumReceiveMessageSize(size uint)

waitGroup() *sync.WaitGroup
}

func newPartyBase(parentContext context.Context, info log.Logger, dbg log.Logger) partyBase {
Expand Down Expand Up @@ -81,10 +84,11 @@ type partyBase struct {
_streamBufferCapacity uint
_maximumReceiveMessageSize uint
_enableDetailedErrors bool
_insecureSkipVerify bool
_originPatterns []string
_insecureSkipVerify bool
_originPatterns []string
info StructuredLogger
dbg StructuredLogger
wg sync.WaitGroup
}

func (p *partyBase) context() context.Context {
Expand Down Expand Up @@ -120,16 +124,16 @@ func (p *partyBase) setKeepAliveInterval(interval time.Duration) {
}

func (p *partyBase) insecureSkipVerify() bool {
return p._insecureSkipVerify
return p._insecureSkipVerify
}
func (p *partyBase) setInsecureSkipVerify(skip bool) {
p._insecureSkipVerify = skip
}

func (p *partyBase) originPatterns() []string {
return p._originPatterns
return p._originPatterns
}
func (p *partyBase) setOriginPatterns(origins []string) {
func (p *partyBase) setOriginPatterns(origins []string) {
p._originPatterns = origins
}

Expand Down Expand Up @@ -173,3 +177,7 @@ func (p *partyBase) setLoggers(info StructuredLogger, dbg StructuredLogger) {
func (p *partyBase) loggers() (info StructuredLogger, debug StructuredLogger) {
return p.info, p.dbg
}

func (p *partyBase) waitGroup() *sync.WaitGroup {
return &p.wg
}

0 comments on commit 9f6cd07

Please sign in to comment.