From 6289eef4e258172d8b9e89947125c14c5b445e36 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Thu, 12 Dec 2024 11:14:34 +0800 Subject: [PATCH] Refine the comments Signed-off-by: JmPotato --- client/pkg/batch/batch_controller.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/pkg/batch/batch_controller.go b/client/pkg/batch/batch_controller.go index afc8c93fea7..322502b754a 100644 --- a/client/pkg/batch/batch_controller.go +++ b/client/pkg/batch/batch_controller.go @@ -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() { @@ -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():