async

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Task

type Task func(i int) (val interface{}, abort bool, err error)

val: the value returned after task execution. err: the error returned during task completion. abort: tells Parallel to return, whether or not all tasks have completed.

type TaskResult

type TaskResult struct {
	Value interface{}
	Error error
}

type TaskResultCh

type TaskResultCh <-chan TaskResult

type TaskResultSet

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

func Parallel

func Parallel(tasks ...Task) (trs *TaskResultSet, ok bool)

Run tasks in parallel, with ability to abort early. Returns ok=false iff any of the tasks returned abort=true. NOTE: Do not implement quit features here. Instead, provide convenient concurrent quit-like primitives, passed implicitly via Task closures. (e.g. it's not Parallel's concern how you quit/abort your tasks).

func (*TaskResultSet) Channels

func (trs *TaskResultSet) Channels() []TaskResultCh

func (*TaskResultSet) FirstError

func (trs *TaskResultSet) FirstError() error

Returns the firstmost (by task index) error as discovered by all previous Reap() calls.

func (*TaskResultSet) FirstValue

func (trs *TaskResultSet) FirstValue() interface{}

Returns the firstmost (by task index) error as discovered by all previous Reap() calls.

func (*TaskResultSet) LatestResult

func (trs *TaskResultSet) LatestResult(index int) (TaskResult, bool)

func (*TaskResultSet) Reap

func (trs *TaskResultSet) Reap() *TaskResultSet

NOTE: Not concurrency safe. Writes results to trs.results without waiting for all tasks to complete.

func (*TaskResultSet) Wait

func (trs *TaskResultSet) Wait() *TaskResultSet

NOTE: Not concurrency safe. Like Reap() but waits until all tasks have returned or panic'd.

Jump to

Keyboard shortcuts

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