Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SlidingWindow ¶
type SlidingWindow struct { Size int // contains filtered or unexported fields }
SlidingWindow has the same role and close to the same API as the Golang sync.WaitGroup but adds a limit of the amount of goroutines started concurrently.
func New ¶
func New(limit int) SlidingWindow
New creates a SlidingWindow. The limit parameter is the maximum amount of goroutines which can be started concurrently.
func (*SlidingWindow) Add ¶
func (s *SlidingWindow) Add()
Add increments the internal WaitGroup counter. It can be blocking if the limit of spawned goroutines has been reached. It will stop blocking when Done is been called.
See sync.WaitGroup documentation for more information.
func (*SlidingWindow) AddWithContext ¶
func (s *SlidingWindow) AddWithContext(ctx context.Context) error
AddWithContext increments the internal WaitGroup counter. It can be blocking if the limit of spawned goroutines has been reached. It will stop blocking when Done is been called, or when the context is canceled. Returns nil on success or an error if the context is canceled before the lock is acquired.
See sync.WaitGroup documentation for more information.
func (*SlidingWindow) Done ¶
func (s *SlidingWindow) Done()
Done decrements the SlidingWindow counter. See sync.WaitGroup documentation for more information.
func (*SlidingWindow) Wait ¶
func (s *SlidingWindow) Wait()
Wait blocks until the SlidingWindow counter is zero. See sync.WaitGroup documentation for more information.