Skip to content

Commit

Permalink
Refine the comments
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Dec 12, 2024
1 parent aff73b6 commit 6289eef
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion client/pkg/batch/batch_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func NewController[T any](maxBatchSize int, finisher FinisherFunc[T], bestBatchO
// It returns nil error if everything goes well, otherwise a non-nil error which means we should stop the service.
// It's guaranteed that if this function failed after collecting some requests, then these requests will be cancelled
// when the function returns, so the caller don't need to clear them manually.
// `tokenCh` is an optional parameter:
// - If it's nil, the batching process will not wait for the token to arrive to continue.
// - If it's not nil, the batching process will wait for a token to arrive before continuing.
// The token will be given back if any error occurs, otherwise it's the caller's responsibility
// to decide when to recycle the signal.
func (bc *Controller[T]) FetchPendingRequests(ctx context.Context, requestCh <-chan T, tokenCh chan struct{}, maxBatchWaitInterval time.Duration) (errRet error) {
var tokenAcquired bool
defer func() {
Expand Down Expand Up @@ -106,7 +111,8 @@ func (bc *Controller[T]) FetchPendingRequests(ctx context.Context, requestCh <-c
}
}

// The token is ready. If the first request didn't arrive, wait for it.
// After the token is ready or it's working without token,
// wait for the first request to arrive.
if bc.collectedRequestCount == 0 {
select {
case <-ctx.Done():
Expand Down

0 comments on commit 6289eef

Please sign in to comment.