concurrency

package
v0.0.36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSemaphoreLocker added in v0.0.36

func NewSemaphoreLocker(opts SemaphoreOpts) sync.Locker

NewSemaphoreLocker return sync.Locker with custom limit of concurrency Semaphore binary implementation of sync.Locker with channel

Types

type Interface

type Interface interface {

	// Use your custom sync.WaitGroup
	WithWg(wg *sync.WaitGroup) Interface

	// Use your custom sync.Locker
	WithLocker(lc sync.Locker) Interface

	// Set maximum worker here. Default is 1
	WithMaxWorker(maxWorker int64) Interface

	// Run the list functions with goroutine. The list method will be cleared after calling this method.
	Do(ctx context.Context) error

	// Added function that will be run async at goroutine. This method already call c.Done() after process is complete
	AddFunc(fn func(ctx context.Context, c Interface))

	// Lock block of code. This like (sync.Mutex{}).Lock()
	Lock()

	// Unlock block of code. This like (sync.Mutex{}).Unlock()
	Unlock()

	// To flag wait group if proccess is done. This like wg.Done()
	Done()

	// Added errors if have error. This method already implement c.Lock() and c.Unlock(). The error will be returned at Do() method if exists. Recommended to use errors.NewWithCode()
	AddError(errs ...error)

	// To clear list functions
	ClearFunc()

	// Get value of maximum worker
	GetMaxWorker() int64

	// Create clone object of this concurrency with empty list function or etc but with same max worker
	Clone() Interface

	// Get list errors
	GetErrors() []error
}

func NewConcurrency

func NewConcurrency() Interface

Do concurrency proccess with custom maximum worker

type SemaphoreOpts added in v0.0.36

type SemaphoreOpts struct {
	Limit int
}

func (*SemaphoreOpts) Default added in v0.0.36

func (so *SemaphoreOpts) Default()

Default set default value for semaphore options if not set

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL