taskrunner

package
v0.0.0-...-a5f7211 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 6 Imported by: 16

Documentation

Overview

Supports starting many cancellable goroutines whose exit and their error codes we can wait on.

Works similar to golang.org/x/sync/errgroup but provides richer logging (tasks are named) and errors

  • The tasks are expected to run forever, until context cancellation (e.g. task stopping before cancellation even with nil error is considered an error).
  • If any of the tasks fail, sibling tasks are canceled as well.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runner

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

func New

func New(ctx context.Context, logger *log.Logger) *Runner

func (*Runner) Done

func (t *Runner) Done() <-chan error

same semantics as Wait(), but returns chan so you can do other stuff while waiting.

NOTE: same note as for Wait()

func (*Runner) Start

func (t *Runner) Start(taskName string, fn func(ctx context.Context) error)

not safe to be called after you call Wait() or Done() not safe for concurrent use

func (*Runner) Wait

func (t *Runner) Wait() error

Returns: - nil if all task exits were expected and errors were nil - err if any of the tasks exited unexpectedly or exit was expected but errored

NOTE: don't have multiple goroutines concurrently use Done() or Wait(). i.e. you can

call Done() and even after that call Wait(), but don't do it concurrently (the
channel only sends one value)

Jump to

Keyboard shortcuts

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