Skip to content

Commit

Permalink
add comments to fix golint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Adolfo García Veytia (Puerco) <adolfo.garcia@uservers.net>
  • Loading branch information
derekperkins authored and puerco committed Jul 23, 2024
1 parent 7db6856 commit 5168f2d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion throttler/throttler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Throttler fills the gap between sync.WaitGroup and manually monitoring your goroutines
// Package throttler fills the gap between sync.WaitGroup and manually monitoring your goroutines
// with channels. The API is almost identical to Wait Groups, but it allows you to set
// a max number of workers that can be running simultaneously. It uses channels internally
// to block until a job completes by calling Done(err) or until all jobs have been completed.
Expand All @@ -18,6 +18,7 @@ import (
"sync"
)

// Throttler stores all the information about the number of workers, the active workers and error information
type Throttler struct {
maxWorkers int
workerCount int
Expand Down Expand Up @@ -120,10 +121,17 @@ func (te multiError) Error() string {
return errString
}

// BatchStartIndex returns the starting index for the next batch. The job count isn't modified
// until th.Throttle() is called, so if you don't call Throttle before executing this
// again, it will return the same index as before
func (t *Throttler) BatchStartIndex() int {
return t.jobsStarted * t.batchSize
}

// BatchEndIndex returns the ending index for the next batch. It either returns the full batch size
// or the remaining amount of jobs. The job count isn't modified
// until th.Throttle() is called, so if you don't call Throttle before executing this
// again, it will return the same index as before.
func (t *Throttler) BatchEndIndex() int {
end := (t.jobsStarted + 1) * t.batchSize
if end > t.batchingTotal {
Expand All @@ -132,6 +140,7 @@ func (t *Throttler) BatchEndIndex() int {
return end
}

// TotalJobs returns the total number of jobs throttler is performing
func (t *Throttler) TotalJobs() int {
return t.totalJobs
}

0 comments on commit 5168f2d

Please sign in to comment.