concurrent

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConcurrencyLimiterTimeout = errors.New("reaches the max concurrency for writing")

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

func NewLimiter

func NewLimiter(ctx context.Context, maxConcurrency int, timeout time.Duration, statistics *metrics.LimitStatistics) *Limiter

NewLimiter creates a limiter based of buffer channel. It limits the concurrency for writing.

func (*Limiter) Do

func (l *Limiter) Do(f func() error) error

type Pool

type Pool interface {
	// Submit enqueues a callable task for a worker to execute.
	//
	// Each submitted task is immediately given to a ready worker.
	// If there are no available workers, the dispatcher starts a new worker,
	// until the maximum number of workers are added.
	//
	// After the maximum number of workers are running, and no workers are ready,
	// execute function will be blocked.
	Submit(ctx context.Context, task *Task)
	// Stopped returns true if this pool has been stopped.
	Stopped() bool
	// Stop stops all goroutines gracefully,
	// all pending tasks will be finished before exit
	Stop()
}

Pool represents the goroutine pool that executes submitted tasks.

func NewPool

func NewPool(name string, maxWorkers int, idleTimeout time.Duration, statistics *metrics.ConcurrentStatistics) Pool

NewPool returns a new worker pool, maxWorkers parameter specifies the maximum number workers that will execute tasks concurrently.

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task represents a task function to be executed by a worker(goroutine).

func NewTask

func NewTask(handle func(), panicHandle func(err error)) *Task

NewTask creates a task.

func (*Task) Exec

func (t *Task) Exec()

Jump to

Keyboard shortcuts

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