fantask

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

fantask: tasks group helper PkgGoDev

Concurrent tasks controller for Go.

What's for?

This tasks controller runs multiple tasks concurrently then wait for either cancellation or one of the task to stop. If any of the conditions is met, the main tasks execution context is canceled, allowing the remaining tasks to stop.

Documentation

Overview

Package fantask provides concurrent tasks control through a shared execution context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CancelWithSignal added in v0.2.0

func CancelWithSignal(tasks *Tasks, sigs ...os.Signal)

CancelWithSignal cancels the tasks execution context when any of the given signals is received. If no signals provided, all signals will be handled.

func IgnoreCanceled

func IgnoreCanceled(err error) error

IgnoreCanceled returns nil on context.Canceled error. Errors are returned unmodified otherwise.

Types

type Task

type Task interface {
	Run(ctx context.Context) error
}

Task is a task interface.

type TaskFunc

type TaskFunc func(ctx context.Context) error

TaskFunc is a task function satisfying the fantask.Task interface.

func (TaskFunc) Run

func (t TaskFunc) Run(ctx context.Context) error

Run executes the task function.

type Tasks added in v0.2.0

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

Tasks is a tasks controller.

func New added in v0.2.0

func New(tasks ...Task) *Tasks

New creates a new tasks controller instance.

func (*Tasks) Append added in v0.2.0

func (t *Tasks) Append(tasks ...Task) *Tasks

Append appends new tasks to the controller tasks list.

func (*Tasks) Cancel added in v0.2.0

func (t *Tasks) Cancel()

Cancel cancels the tasks execution context.

func (*Tasks) Run added in v0.2.0

func (t *Tasks) Run(ctx context.Context) error

Run executes all tasks concurrently, waiting for termination.

Jump to

Keyboard shortcuts

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