Documentation
¶
Overview ¶
Package coma limits how many goroutines run concurrently and waits for all of them to finish.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("coma: manager is shut down")
ErrClosed is returned by Acquire and AcquireContext when Wait has been called.
Functions ¶
This section is empty.
Types ¶
type ConcurrencyManager ¶
type ConcurrencyManager struct {
// contains filtered or unexported fields
}
ConcurrencyManager limits how many goroutines can run concurrently.
func New ¶
func New(max int32) *ConcurrencyManager
New creates a ConcurrencyManager that allows at most max concurrently running goroutines.
func (*ConcurrencyManager) Acquire ¶
func (c *ConcurrencyManager) Acquire() error
Acquire blocks until a slot is available and claims it for a new goroutine. If Wait has been called, Acquire returns ErrClosed.
func (*ConcurrencyManager) AcquireContext ¶
func (c *ConcurrencyManager) AcquireContext(ctx context.Context) error
AcquireContext blocks until a slot is available and claims it for a new goroutine, or returns ctx.Err() if the context is done first. If Wait has been called, AcquireContext returns ErrClosed.
func (*ConcurrencyManager) Release ¶
func (c *ConcurrencyManager) Release()
Release marks a goroutine as finished and releases one slot.
func (*ConcurrencyManager) RunningCount ¶
func (c *ConcurrencyManager) RunningCount() int32
RunningCount returns the number of currently running goroutines.
func (*ConcurrencyManager) Wait ¶
func (c *ConcurrencyManager) Wait()
Wait waits until all goroutines are done. Wait is terminal, meaning ConcurrencyManager cannot be reused. Wait is not safe for concurrent use - calling it from multiple goroutines at once may panic. A repeated call from the same goroutine is a safe no-op.