taskqueue

package module
v0.0.0-...-018b5eb Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Example
tasks, err := taskqueue.FromList([]taskqueue.Task{{
	Name: "init",
}, {
	Name: "partA",
	Deps: []string{"init"},
}, {
	Name: "partB",
	Deps: []string{"partB"},
}, {
	Name: "finalize",
	Deps: []string{"partA", "partB"},
}})
if err != nil {
	fmt.Println(err.Error())
	return
}

work, done := taskqueue.Start(tasks)
taskqueue.RunOnPool(work, done, pool.New(), func(name string) {
	fmt.Printf("Running %s\n", name)
})

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrDuplicateName = errors.New("duplicate task name")
View Source
var ErrEmptyName = errors.New("task name is empty")
View Source
var ErrNameMismatch = errors.New("task name mismatch")
View Source
var ErrUnknownDep = errors.New("unknown dependency name")

Functions

func RunOnContextPool

func RunOnContextPool(work <-chan string, completed chan<- string, pool interface {
	Go(func(context.Context) error)
	Wait() error
}, handler func(context.Context, string) error) error

For use with conc.ContextPool

func RunOnErrorPool

func RunOnErrorPool(work <-chan string, completed chan<- string, pool interface {
	Go(func() error)
	Wait() error
}, handler func(string) error) error

For use with conc.ErrorPool

func RunOnPool

func RunOnPool(work <-chan string, completed chan<- string, pool interface {
	Go(func())
	Wait()
}, handler func(string))

For use with conc.Pool

func RunOnResultContextPool

func RunOnResultContextPool[T any](work <-chan string, completed chan<- string, pool interface {
	Go(func(context.Context) (T, error))
	Wait() ([]T, error)
}, handler func(context.Context, string) (T, error)) ([]T, error)

For use with conc.ResultContextPool

func RunOnResultErrorPool

func RunOnResultErrorPool[T any](work <-chan string, completed chan<- string, pool interface {
	Go(func() (T, error))
	Wait() ([]T, error)
}, handler func(string) (T, error)) ([]T, error)

For use with conc.ResultErrorPool

func RunOnResultPool

func RunOnResultPool[T any](work <-chan string, completed chan<- string, pool interface {
	Go(func() T)
	Wait() []T
}, handler func(string) T) []T

For use with conc.ResultPool

func Start

func Start(tasks TaskSet) (start <-chan string, done chan<- string)

Starts a scheduler for the tasks in the task set.

Names of tasks ready to be executed are sent to the returned start channel. On completion of a task, its name must be sent to the done channel.

Tasks will only be scheduled concurrently with other tasks in the same group. This also applies to the default group indicated by an empty group name.

The scheduler closes the start channel on exit. It will exit on completion of all tasks, or if no further tasks are schedulable (i.e. there is a deadlock), or if the done channel is closed.

Types

type Task

type Task struct {
	Name  string
	Deps  []string
	Group string
}

type TaskSet

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

func FromList

func FromList(tasks []Task) (TaskSet, error)

func FromMap

func FromMap(tasks map[string]Task) (TaskSet, error)

func FromMapUnchecked

func FromMapUnchecked(tasks map[string]Task) TaskSet

func FromMapper

func FromMapper[T any](items []T, namer func(T) string, deps func(T) []string, grouper func(T) string) (TaskSet, error)

Jump to

Keyboard shortcuts

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