taskrunner

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PreloadedTaskRunner

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

PreloadedTaskRunner is a task runner that invokes a series of preloaded tasks, running until the tasks are completed, the context is canceled or an error is returned by one of the tasks (which cancels the context).

func NewPreloadedTaskRunner

func NewPreloadedTaskRunner(ctx context.Context, concurrencyLimit uint16, initialCapacity int) *PreloadedTaskRunner

func (*PreloadedTaskRunner) Add

func (tr *PreloadedTaskRunner) Add(f TaskFunc)

Add adds the given task function to be run.

func (*PreloadedTaskRunner) Start

func (tr *PreloadedTaskRunner) Start()

Start starts running the tasks in the task runner. This does *not* wait for the tasks to complete, but rather returns immediately.

func (*PreloadedTaskRunner) StartAndWait

func (tr *PreloadedTaskRunner) StartAndWait() error

StartAndWait starts running the tasks in the task runner and waits for them to complete.

type TaskFunc

type TaskFunc func(ctx context.Context) error

TaskFunc defines functions representing tasks.

type TaskRunner

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

TaskRunner is a helper which runs a series of scheduled tasks against a defined limit of goroutines.

func NewTaskRunner

func NewTaskRunner(ctx context.Context, concurrencyLimit uint16) *TaskRunner

NewTaskRunner creates a new task runner with the given starting context and concurrency limit. The TaskRunner will schedule no more goroutines that the specified concurrencyLimit. If the given context is canceled, then all tasks started after that point will also be canceled and the error returned. If a task returns an error, the context provided to all tasks is also canceled.

func (*TaskRunner) Schedule

func (tr *TaskRunner) Schedule(f TaskFunc)

Schedule schedules a task to be run. This is safe to call from within another task handler function and immediately returns.

func (*TaskRunner) Wait

func (tr *TaskRunner) Wait() error

Wait waits for all tasks to be completed, or a task to raise an error, or the parent context to have been canceled.

Jump to

Keyboard shortcuts

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