async

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Routine

func Routine(fn func()) <-chan struct{}

Types

type Task

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

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