executor

package
v0.0.0-...-6bc7ac3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(wp *WorkerPool, task func())

Execute adds a task to the task queue to be processed by the workers

Types

type Future

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

func NewFuture

func NewFuture[T any](iFut *IFuture, defaultValue T) *Future[T]

func Submit

func Submit[T any](wp *WorkerPool, defaultValue T, task func()) *Future[T]

func SubmitWithError

func SubmitWithError[T any](wp *WorkerPool, defaultValue T, task func() (T, error)) *Future[T]

SubmitWithError adds a task to the task queue to be processed by the workers and logs error if there was one

func (*Future[T]) CastOrDefault

func (f *Future[T]) CastOrDefault(result interface{}, err error) (T, error)

func (*Future[T]) Get

func (f *Future[T]) Get() (T, error)

func (*Future[T]) HandleError

func (f *Future[T]) HandleError(handleError func(error))

func (*Future[T]) IsDone

func (f *Future[T]) IsDone() bool

func (*Future[T]) IsRunning

func (f *Future[T]) IsRunning() bool

func (*Future[T]) Map

func (f *Future[T]) Map(next func(T) (T, error)) *Future[T]

func (*Future[T]) ThenAccept

func (f *Future[T]) ThenAccept(next func(T, error))

func (*Future[T]) ThenApply

func (f *Future[T]) ThenApply(next func(T, error) (T, error)) *Future[T]

func (*Future[T]) ThenDo

func (f *Future[T]) ThenDo(next func())

type IFuture

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

func NewIFuture

func NewIFuture[T any](payload func() (T, error), pool *WorkerPool) *IFuture

func (*IFuture) FlatMap

func (f *IFuture) FlatMap(next func(interface{}) (interface{}, error)) interface{}

func (*IFuture) Get

func (f *IFuture) Get() (interface{}, error)

func (*IFuture) IsDone

func (f *IFuture) IsDone() bool

func (*IFuture) IsRunning

func (f *IFuture) IsRunning() bool

func (*IFuture) IsRunningOrDone

func (f *IFuture) IsRunningOrDone() bool

func (*IFuture) Map

func (f *IFuture) Map(next func(interface{}) (interface{}, error)) *IFuture

func (*IFuture) ThenAccept

func (f *IFuture) ThenAccept(next func(interface{}, error))

func (*IFuture) ThenApply

func (f *IFuture) ThenApply(next func(interface{}, error) (interface{}, error)) *IFuture

func (*IFuture) ThenDo

func (f *IFuture) ThenDo(next func())

type Task

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

Task represents a unit of work to be processed by the worker pool

func NewTask

func NewTask(fut *IFuture) Task

NewTask initializes a new Task with a unique ID and a payload function

type WorkerPool

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

WorkerPool is a struct that manages a pool of workers to process tasks

func NewWorkerPool

func NewWorkerPool() *WorkerPool

NewWorkerPool initializes a new WorkerPool with the optimal number of workers

func NewWorkerPoolWithMax

func NewWorkerPoolWithMax(maxWorkers int) *WorkerPool

NewWorkerPool initializes a new WorkerPool with the optimal number of workers

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Stop gracefully shuts down the worker pool by closing the task queue and waiting for workers to finish

func (*WorkerPool) Wait

func (wp *WorkerPool) Wait()

Jump to

Keyboard shortcuts

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