Skip to content

Commit

Permalink
fix(linkedbuffer): fix bufferHasElements channel length
Browse files Browse the repository at this point in the history
  • Loading branch information
alitto committed Nov 10, 2024
1 parent f1d2a44 commit 21dac3d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test:
go test -race -v -timeout 1m ./...
go test -race -v -timeout 1m -count=3 ./...

coverage:
go test -race -v -timeout 1m -coverprofile=coverage.out -covermode=atomic ./...
2 changes: 1 addition & 1 deletion internal/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewDispatcher[T any](ctx context.Context, dispatchFunc func([]T), batchSize
dispatcher := &Dispatcher[T]{
ctx: ctx,
buffer: linkedbuffer.NewLinkedBuffer[T](10, batchSize),
bufferHasElements: make(chan struct{}, 1),
bufferHasElements: make(chan struct{}, 2), // This channel needs to have size 2 in case an element is written to the buffer while the dispatcher is processing elements
dispatchFunc: dispatchFunc,
batchSize: batchSize,
closed: atomic.Bool{},
Expand Down

0 comments on commit 21dac3d

Please sign in to comment.