Throttler stores all the information about the number of workers, the active workers and error information
type Throttler struct {
// contains filtered or unexported fields
}
▹ Example
▹ Example (Errors)
func New(maxWorkers, totalJobs int) *Throttler
New returns a Throttler that will govern the max number of workers and will work with the total number of jobs. It panics if maxWorkers < 1.
func NewBatchedThrottler(maxWorkers, batchingTotal, batchSize int) *Throttler
NewBatchedThrottler returns a Throttler (just like New), but also enables batching.
func (t *Throttler) BatchEndIndex() int
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) BatchStartIndex() int
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) Done(err error)
Done lets Throttler know that a job has been completed so that another worker can be activated. If Done is called less times than totalJobs, Throttle will block forever
func (t *Throttler) Err() error
Err returns an error representative of all errors caught by throttler
func (t *Throttler) Errs() []error
Errs returns a slice of any errors that were received from calling Done()
func (t *Throttler) SetMaxWorkers(maxWorkers int)
SetMaxWorkers lets you change the total number of workers that can run concurrently. NOTE: If all workers are currently running, this setting is not guaranteed to take effect until one of them completes and Throttle() is called again
func (t *Throttler) Throttle() int
Throttle works similarly to sync.WaitGroup, except inside your goroutine dispatch loop rather than after. It will not block until the number of active workers matches the max number of workers designated in the call to NewThrottler or all of the jobs have been dispatched. It stops blocking when Done has been called as many times as totalJobs.
func (t *Throttler) TotalJobs() int
TotalJobs returns the total number of jobs throttler is performing