concurrent

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAll

func GetAll[T any](ctx context.Context, futures ...Future[T]) ([]T, error)

Types

type Future

type Future[T any] struct {
	// contains filtered or unexported fields
}

Future provides a way to easily start a go routine and get the result of the go routine later. Avoid building any mapping functionality into futures, as that can make them difficult to reason about

func SubmitFuture

func SubmitFuture[T any](ctx context.Context, runner GoroutineRunner, fn func() (T, error)) (Future[T], error)

SubmitFuture creates a new future that will run the given function in a go routine.

This function will potentially block depending on the underlying GoroutineRunner implementation. E.g., the GoroutineRunner could be a worker pool with a limited number of workers, in which case this function could block until a worker is available.

func (Future[T]) Get

func (f Future[T]) Get(ctx context.Context) (T, error)

type GoroutineRunner

type GoroutineRunner interface {
	// Go starts a go routine and returns an error if the go routine could not be started.
	Go(context.Context, func()) error
}

Future provides a way to easily start a go routine and get the result of the go routine later. Avoid building any mapping functionality into futures, as that can make them difficult to reason about

func NewSynchronousGoroutineRunner

func NewSynchronousGoroutineRunner() GoroutineRunner

NewSynchronousGoroutineRunner creates a new goroutine runner that runs the goroutines synchronously

type LimitedGoroutineRunner

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

func NewGoroutineLimiter

func NewGoroutineLimiter(limit int64) *LimitedGoroutineRunner

NewGoroutineLimiter creates a new GoroutineRunner that limits the number of goroutines. No more than the limit number of goroutines can be running at the same time.

func (*LimitedGoroutineRunner) Go

func (l *LimitedGoroutineRunner) Go(ctx context.Context, fn func()) error

type SynchronousGoroutineRunner

type SynchronousGoroutineRunner struct{}

func (*SynchronousGoroutineRunner) Go

func (r *SynchronousGoroutineRunner) Go(_ context.Context, fn func()) error

Jump to

Keyboard shortcuts

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