task

package
v0.0.0-...-927ded2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package task implements a simple asynchronous task management scheme.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShuttingDown = errors.New("shutting down: cannot start a new task")
	ErrNoSuchTask   = errors.New("no such task")
)

Functions

This section is empty.

Types

type Id

type Id string

Id identifies a task to a manager.

type Interface

type Interface interface {
	Run() (interface{}, error)
}

Interface is the common interface implemented for a task that can be managed by a Manager.

Run executes the task and returns the result and/or an error.

type Manager

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

Manager keeps track of a set of tasks. Currently, it keeps tasks forever but it should have a way of expiring tasks.

func (*Manager) Shutdown

func (tm *Manager) Shutdown(ctx context.Context) error

Shutdown disallows new tasks from being started and waits until the existing tasks all complete. This returns an error only if the provided context is done before all the tasks have completed.

func (*Manager) Start

func (tm *Manager) Start(task Interface) (Id, error)

Start initiates the execution of the provided task and returns the id. If Shutdown has been called, then this will return ErrShuttingDown.

func (*Manager) Wait

func (tm *Manager) Wait(ctx context.Context, id Id) (interface{}, error)

Wait for the given task to be completed and return the result & error output of the task. Once a task completes, subsequent calls to this function will immediately return the outputs. If the provided context finishes before the task has completed, then the context error (cancelled or timeout) will be returned.

NOTE(aroman) Probably this should only be allowed to be called once succesfully (that is, not including the context timeout) and then expire the task to prevent excessive memory growth.

Jump to

Keyboard shortcuts

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