future

package
v0.0.0-...-3bf81a3 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback[T any] func(context.Context) T

type Executor

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

func NewExecutor

func NewExecutor[T any](limit int) *Executor[T]

func (*Executor[T]) Close

func (exec *Executor[T]) Close()

func (*Executor[T]) Submit

func (exec *Executor[T]) Submit(task *Task[T]) Future[T]

func (*Executor[T]) Wait

func (exec *Executor[T]) Wait()

type Future

type Future[T any] interface {
	ID() string
	Get() (T, error)
	GetWithTimeout(timeout time.Duration) (T, error)
	Cancel(error)
	IsDone() bool
	State() State
}

func Submit

func Submit[T any](task *Task[T]) Future[T]

Submit submits a task immediately without waiting for an executor to run.

type State

type State int
const (
	PENDING State = iota
	INCOMPLETE
	COMPLETED
)

func (State) String

func (s State) String() string

type Task

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

Task T is the return type of the task, see Callback.

func NewTask

func NewTask[T any](ctx context.Context, id string, timeout time.Duration, callback Callback[T]) *Task[T]

func (*Task[T]) Cancel

func (t *Task[T]) Cancel(err error)

func (*Task[T]) IsDone

func (t *Task[T]) IsDone() bool

func (*Task[T]) Result

func (t *Task[T]) Result() (T, error)

func (*Task[T]) Run

func (t *Task[T]) Run(wg *sync.WaitGroup)

func (*Task[T]) State

func (t *Task[T]) State() State

Jump to

Keyboard shortcuts

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