Skip to content

Commit

Permalink
[chore] Use chan struct{} instead of bool to reduce space (#12232)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Feb 1, 2025
1 parent 7b671b8 commit 51672ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions exporter/internal/queue/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type BaseBatcher struct {
queue exporterqueue.Queue[internal.Request]
// TODO: Remove when the -1 hack for testing is removed.
maxWorkers int
workerPool chan bool
workerPool chan struct{}
exportFunc func(ctx context.Context, req internal.Request) error
stopWG sync.WaitGroup
}
Expand All @@ -50,11 +50,11 @@ func newBaseBatcher(batchCfg exporterbatcher.Config,
exportFunc func(ctx context.Context, req internal.Request) error,
maxWorkers int,
) BaseBatcher {
var workerPool chan bool
var workerPool chan struct{}
if maxWorkers > 0 {
workerPool = make(chan bool, maxWorkers)
workerPool = make(chan struct{}, maxWorkers)
for i := 0; i < maxWorkers; i++ {
workerPool <- true
workerPool <- struct{}{}
}
}
return BaseBatcher{
Expand All @@ -80,7 +80,7 @@ func (qb *BaseBatcher) flush(ctx context.Context, req internal.Request, dones []
done(err)
}
if qb.workerPool != nil {
qb.workerPool <- true
qb.workerPool <- struct{}{}
}
}()
}
6 changes: 3 additions & 3 deletions exporter/internal/queue/default_batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type DefaultBatcher struct {
currentBatchMu sync.Mutex
currentBatch *batch
timer *time.Timer
shutdownCh chan bool
shutdownCh chan struct{}
}

func (qb *DefaultBatcher) resetTimer() {
Expand All @@ -38,7 +38,7 @@ func (qb *DefaultBatcher) startReadingFlushingGoroutine() {
// Read() blocks until the queue is non-empty or until the queue is stopped.
ctx, req, done, ok := qb.queue.Read(context.Background())
if !ok {
qb.shutdownCh <- true
close(qb.shutdownCh)
return
}

Expand Down Expand Up @@ -139,7 +139,7 @@ func (qb *DefaultBatcher) Start(_ context.Context, _ component.Host) error {
return nil
}

qb.shutdownCh = make(chan bool, 1)
qb.shutdownCh = make(chan struct{}, 1)

if qb.batchCfg.FlushTimeout == 0 {
qb.timer = time.NewTimer(math.MaxInt)
Expand Down

0 comments on commit 51672ad

Please sign in to comment.