Skip to content

Commit 6268580

Browse files
committed
chore: fix godoc
1 parent 660033e commit 6268580

3 files changed

Lines changed: 80 additions & 80 deletions

File tree

batch.go

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,47 @@ type ProcessorSetup[T any, B any] struct {
2121

2222
// IProcessor provides common methods of a [Processor].
2323
type 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.
6565
type 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.
108108
func (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.
117117
func (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.
129129
func (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.
189189
func (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.
262262
func (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.
325325
func (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.
465465
func (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.
516516
func (p *Processor[T, B]) Drain(ctx context.Context) error {
517517
if p.IsDisabled() {
518518
return nil

builtin.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ type KeyVal[K any, V any] struct {
1010
val V
1111
}
1212

13-
// InitBatchFn function to create empty batch.
14-
// Accept max item limit, can be 1 (disabled), -1 (unlimited) or any positive number.
13+
// InitBatchFn function to create an empty batch.
14+
// Accept max item limit can be 1 (disabled), -1 (unlimited) or any positive number.
1515
// The InitBatchFn must never panic.
1616
type InitBatchFn[B any] func(int64) B
1717

18-
// MergeToBatchFn function to add an item to batch.
18+
// MergeToBatchFn function to add an item to the batch.
1919
// The MergeToBatchFn must never panic.
2020
type MergeToBatchFn[B any, T any] func(B, T) B
2121

@@ -24,7 +24,7 @@ type MergeToBatchFn[B any, T any] func(B, T) B
2424
// The SplitBatchFn must never panic.
2525
type SplitBatchFn[B any] func(B, int64) []B
2626

27-
// CountBatchFn function to count the number of item in a batch.
27+
// CountBatchFn function to count the number of items in a batch.
2828
// The CountBatchFn must never panic.
2929
type CountBatchFn[B any] func(B) int64
3030

@@ -33,7 +33,7 @@ type CountBatchFn[B any] func(B) int64
3333
type ProcessBatchFn[B any] func(B, int64) error
3434

3535
// RecoverBatchFn function to handle an error batch.
36-
// Each RecoverBatchFn can further return error to enable the next RecoverBatchFn in the chain.
36+
// Each RecoverBatchFn can further return an error to enable the next RecoverBatchFn in the chain.
3737
// The RecoverBatchFn must never panic.
3838
//
3939
// Accept the current batch and a counter with the previous error.
@@ -85,10 +85,10 @@ func NewSelfMapProcessor[T any, K comparable](keyExtractor ExtractFn[T, K], comb
8585
}
8686

8787
// InitMap is [InitBatchFn] that allocate a map.
88-
// It uses the default size for map, as the size of item may be much larger than the size of map after merged.
89-
// However, if you properly configured [WithBatchCounter] to count the size of map
88+
// It uses the default size for the map, as the size of items may be much larger than the size of the map after merged.
89+
// However, if you properly configured [WithBatchCounter] to count the size of the map
9090
// and [WithMaxItem] to a reasonable value,
91-
// you may benefit from specifying the size of map using your own [InitBatchFn].
91+
// you may benefit from specifying the size of the map using your own [InitBatchFn].
9292
// It is recommended to use [NewMapProcessor] instead if possible.
9393
func InitMap[K comparable, V any](i int64) map[K]V {
9494
if i == 0 {
@@ -104,9 +104,9 @@ type ExtractFn[T any, V any] func(T) V
104104
type CombineFn[T any] func(T, T) T
105105

106106
// addToMapUsing create [MergeToBatchFn]
107-
// that add item to map using [KeyVal] [ExtractFn] and apply [CombineFn] if key duplicated.
108-
// The original value will be passed as 1st parameter to the [CombineFn].
109-
// If [CombineFn] is nil, duplicated key will be replaced.
107+
// that add item to the map using [KeyVal] [ExtractFn] and apply [CombineFn] if key duplicated.
108+
// The original value will be passed as the 1st parameter to the [CombineFn].
109+
// If [CombineFn] is nil, any duplicated key will be replaced.
110110
func addToMapUsing[T any, K comparable, V any](extractor ExtractFn[T, KeyVal[K, V]], combiner CombineFn[V]) MergeToBatchFn[map[K]V, T] {
111111
if combiner == nil {
112112
return func(m map[K]V, t T) map[K]V {
@@ -129,8 +129,8 @@ func addToMapUsing[T any, K comparable, V any](extractor ExtractFn[T, KeyVal[K,
129129

130130
// addSelfToMapUsing create a [MergeToBatchFn] that add self as item to map using key [ExtractFn]
131131
// and apply [CombineFn] if key duplicated.
132-
// The original value will be passed as 1st parameter to the [CombineFn].
133-
// If [CombineFn] is nil, duplicated key will be replaced.
132+
// The original value will be passed as the 1st parameter to the [CombineFn].
133+
// If [CombineFn] is nil, any duplicated key will be replaced.
134134
func addSelfToMapUsing[T any, K comparable](keyExtractor ExtractFn[T, K], combiner CombineFn[T]) MergeToBatchFn[map[K]T, T] {
135135
if combiner == nil {
136136
return func(m map[K]T, t T) map[K]T {

0 commit comments

Comments
 (0)