@@ -21,47 +21,47 @@ type ProcessorSetup[T any, B any] struct {
2121
2222// IProcessor provides common methods of a [Processor].
2323type IProcessor [T any , B any ] interface {
24- // Put add item to the processor.
24+ // Put adds item to the processor.
2525 // If the context is canceled and the item is not added, then this method will return false.
26- // The context passed in only control the put step, after item added to the processor,
26+ // The context passed in only controls the put step. After the item was added to the processor,
2727 // the processing will not be canceled by this context.
2828 Put (ctx context.Context , item T ) bool
2929 // PutAll add all items to the processor.
3030 // If the context is canceled, then this method will return the number of items added to the processor.
3131 PutAll (ctx context.Context , items []T ) int
3232
33- // Merge add item to the processor using merge function.
33+ // Merge add item to the processor using the merge function.
3434 // If the context is canceled and the item is not added, then this method will return false.
35- // The context passed in only control the put step, after item added to the processor,
35+ // The context passed in only controls the put step. After the item was added to the processor,
3636 // the processing will not be canceled by this context.
3737 Merge (ctx context.Context , item T , merge MergeToBatchFn [B , T ]) bool
38- // MergeAll add all items to the processor using merge function.
38+ // MergeAll add all items to the processor using a merge function.
3939 // If the context is canceled, then this method will return the number of items added to the processor.
4040 MergeAll (ctx context.Context , items []T , merge MergeToBatchFn [B , T ]) int
4141
42- // ApproxItemCount return number of current item in processor, approximately.
42+ // ApproxItemCount return number of current items in the processor, approximately.
4343 ApproxItemCount () int64
44- // ItemCount return number of current item in processor.
45- // If the context is canceled, then this method will return approximate item count and false.
44+ // ItemCount return number of current items in the processor.
45+ // If the context is canceled, then this method will return an approximate item count and false.
4646 ItemCount (ctx context.Context ) (int64 , bool )
4747 // Close stop the processor.
48- // This method may process the left-over batch on caller thread.
49- // Context can be used to provide deadline for this method.
48+ // This method may process the left-over batch on the caller thread.
49+ // Context can be used to provide a deadline for this method.
5050 Close (ctx context.Context ) error
5151 // Stop the processor.
5252 // This method does not process leftover batch.
5353 Stop (ctx context.Context ) error
54- // Drain force process batch util the batch is empty.
55- // This method may process the batch on caller thread.
56- // Context can be used to provide deadline for this method.
54+ // Drain force processing the batch until the batch is empty.
55+ // This method may process the batch on the caller thread.
56+ // Context can be used to provide a deadline for this method.
5757 Drain (ctx context.Context ) error
5858 // Flush force process the current batch.
59- // This method may process the batch on caller thread.
60- // Context can be used to provide deadline for this method.
59+ // This method may process the batch on the caller thread.
60+ // Context can be used to provide a deadline for this method.
6161 Flush (ctx context.Context ) error
6262}
6363
64- // Processor a processor that is running and can process item.
64+ // Processor is a processor that is running and can process item.
6565type Processor [T any , B any ] struct {
6666 ProcessorSetup [T , B ]
6767 runConfig [B ]
@@ -87,7 +87,7 @@ type Processor[T any, B any] struct {
8787
8888// NewProcessor create a ProcessorSetup using specified functions.
8989// See [ProcessorSetup.Configure] and [Option] for available configuration.
90- // The result [ProcessorSetup] is in setup state.
90+ // The result [ProcessorSetup] is in the setup state.
9191// Call [ProcessorSetup.Run] with a handler to create a [Processor] that can accept item.
9292// It is recommended to set at least maxWait by [WithMaxWait] or maxItem by [WithMaxItem].
9393// By default, the processor operates similarly to aggressive mode, use Configure to change its behavior.
@@ -104,16 +104,16 @@ func NewProcessor[T any, B any](initFn InitBatchFn[B], mergeFn MergeToBatchFn[B,
104104 }
105105}
106106
107- // Configure apply [Option] to this processor setup.
107+ // Configure applies [Option] to this processor setup.
108108func (p ProcessorSetup [T , B ]) Configure (options ... Option ) ProcessorSetup [T , B ] {
109109 for i := range options {
110110 options [i ](& p .processorConfig )
111111 }
112112 return p
113113}
114114
115- // ItemCount return number of current item in processor.
116- // If the context is canceled, then this method will return approximate item count and false.
115+ // ItemCount return number of current items in the processor.
116+ // If the context is canceled, then this method will return an approximate item count and false.
117117func (p * Processor [T , B ]) ItemCount (ctx context.Context ) (int64 , bool ) {
118118 select {
119119 case p .blocked <- struct {}{}:
@@ -124,7 +124,7 @@ func (p *Processor[T, B]) ItemCount(ctx context.Context) (int64, bool) {
124124 return p .counter , true
125125}
126126
127- // ApproxItemCount return number of current item in processor.
127+ // ApproxItemCount return number of current items in processor.
128128// This method does not block, so the counter may not be accurate.
129129func (p * Processor [T , B ]) ApproxItemCount () int64 {
130130 return p .counter
@@ -166,15 +166,15 @@ func (p ProcessorSetup[T, B]) Run(process ProcessBatchFn[B], options ...RunOptio
166166 }
167167
168168 if p .maxWait < 0 && p .maxItem >= 0 {
169- processor .waitUtilFullDispatch ()
169+ processor .waitUntilFullDispatch ()
170170 return processor
171171 }
172172
173173 if p .maxWait == 0 {
174174 if processor .notEmpty != nil {
175175 processor .continuousDispatch ()
176176 } else {
177- processor .waitUtilFullContinuousDispatch ()
177+ processor .waitUntilFullContinuousDispatch ()
178178 }
179179 return processor
180180 }
@@ -184,8 +184,8 @@ func (p ProcessorSetup[T, B]) Run(process ProcessBatchFn[B], options ...RunOptio
184184}
185185
186186// continuousDispatch create a dispatcher routine that,
187- // when batch is empty, wait util it not empty,
188- // else process the remaining batch util it became empty.
187+ // when the batch is empty, wait until it is not empty,
188+ // else process the remaining batch until it became empty.
189189func (p * Processor [T , B ]) continuousDispatch () {
190190 if p .notEmpty == nil {
191191 // Should never happen.
@@ -226,11 +226,11 @@ func (p *Processor[T, B]) continuousDispatch() {
226226 }()
227227}
228228
229- // waitUtilFullContinuousDispatch create a dispatcher routine that,
230- // when batch is empty, wait util it full,
231- // else process the remaining batch util it became empty.
229+ // waitUntilFullContinuousDispatch create a dispatcher routine that,
230+ // when the batch is empty, wait until it is full,
231+ // else process the remaining batch until it became empty.
232232// maxItem must be specified by [WithMaxItem].
233- func (p * Processor [T , B ]) waitUtilFullContinuousDispatch () {
233+ func (p * Processor [T , B ]) waitUntilFullContinuousDispatch () {
234234 go func () {
235235 for {
236236 select {
@@ -241,7 +241,7 @@ func (p *Processor[T, B]) waitUtilFullContinuousDispatch() {
241241 break
242242 }
243243 <- p .blocked
244- // if the batch is empty then wait util full to process.
244+ // if the batch is empty then wait until full to process.
245245 select {
246246 case <- p .full :
247247 p .doProcessAndRelease (p .isBlockWhileProcessing )
@@ -257,7 +257,7 @@ func (p *Processor[T, B]) waitUtilFullContinuousDispatch() {
257257 }()
258258}
259259
260- // timedDispatch create a dispatcher routine that wait util the batch is full or AT LEAST maxWait elapsed.
260+ // timedDispatch create a dispatcher routine that waits until the batch is full or AT LEAST maxWait elapsed.
261261// when maxWait is passed and the batch is empty, it will reset the timer to avoid processing only one item.
262262func (p * Processor [T , B ]) timedDispatch () {
263263 go func () {
@@ -268,7 +268,7 @@ func (p *Processor[T, B]) timedDispatch() {
268268 select {
269269 case p .blocked <- struct {}{}:
270270 // if empty, then reset the timer.
271- // this avoids the first item getting processed immediately after a long wait.
271+ // this avoids the first item to be processed immediately after a long wait.
272272 if p .counter == 0 && ! p .isHardMaxWait {
273273 <- p .blocked
274274 break
@@ -294,9 +294,9 @@ func (p *Processor[T, B]) timedDispatch() {
294294 }()
295295}
296296
297- // waitUtilFullDispatch create a dispatcher routine that wait util the batch is full.
297+ // waitUntilFullDispatch create a dispatcher routine that waits until the batch is full.
298298// maxItem must be specified using [WithMaxItem].
299- func (p * Processor [T , B ]) waitUtilFullDispatch () {
299+ func (p * Processor [T , B ]) waitUntilFullDispatch () {
300300 go func () {
301301 for {
302302 select {
@@ -321,7 +321,7 @@ func (p *Processor[T, B]) Put(ctx context.Context, item T) bool {
321321 return p .Merge (ctx , item , p .mergeFn )
322322}
323323
324- // Merge add item to the processor using merge function.
324+ // Merge add item to the processor using a merge function.
325325func (p * Processor [T , B ]) Merge (ctx context.Context , item T , merge MergeToBatchFn [B , T ]) bool {
326326 if ctx .Err () != nil {
327327 return false
@@ -365,7 +365,7 @@ func (p *Processor[T, B]) Merge(ctx context.Context, item T, merge MergeToBatchF
365365 }
366366 }
367367 if p .maxItem > - 1 && p .counter >= p .maxItem {
368- // Block util processed.
368+ // Block until processed.
369369 p .full <- struct {}{}
370370 return true
371371 }
@@ -381,7 +381,7 @@ func (p *Processor[T, B]) PutAll(ctx context.Context, items []T) int {
381381 return p .MergeAll (ctx , items , p .mergeFn )
382382}
383383
384- // MergeAll add all items to the processor using merge function.
384+ // MergeAll add all items to the processor using a merge function.
385385// If the context is canceled, then this method will return the number of items added to the processor.
386386// The processing order is the same as the input list,
387387// so the output can also be used to determine the next item to process if you want to retry or continue processing.
@@ -448,7 +448,7 @@ func (p *Processor[T, B]) MergeAll(ctx context.Context, items []T, merge MergeTo
448448 }
449449 }
450450 if p .maxItem > - 1 && p .counter >= p .maxItem {
451- // Block util processed.
451+ // Block until processed.
452452 p .full <- struct {}{}
453453 continue
454454 }
@@ -458,9 +458,9 @@ func (p *Processor[T, B]) MergeAll(ctx context.Context, items []T, merge MergeTo
458458}
459459
460460// Close stop the processor.
461- // This method will process the leftover branch on caller thread.
461+ // This method will process the leftover branch on the caller thread.
462462//
463- // Context can be used to provide deadline for this method,
463+ // Context can be used to provide a deadline for this method,
464464// Context does not affect already in processing batch.
465465func (p * Processor [T , B ]) Close (ctx context.Context ) error {
466466 if p .IsDisabled () {
@@ -510,9 +510,9 @@ func (p *Processor[T, B]) Stop(ctx context.Context) error {
510510 return nil
511511}
512512
513- // Drain force process batch util the batch is empty.
514- // This method always processes the batch on caller thread.
515- // ctx can be used to provide deadline for this method.
513+ // Drain force processing batch until the batch is empty.
514+ // This method always processes the batch on the caller thread.
515+ // ctx can be used to provide a deadline for this method.
516516func (p * Processor [T , B ]) Drain (ctx context.Context ) error {
517517 if p .IsDisabled () {
518518 return nil
0 commit comments