taker: github.com/alexanderGugel/taker Index | Files

package taker

import "github.com/alexanderGugel/taker"

Index

Package Files

do_whilst.go force_series.go forever.go parallel.go parallel_limit.go race.go retry.go series.go taker.go task.go timeout.go times.go until.go whilst.go

func DoWhilst Uses

func DoWhilst(task Task, test Test) error

DoWhilst runs the task as long as the test passes. This is the post-check version of whilst. This means the task will be run at least once.

func ForceSeries Uses

func ForceSeries(tasks ...Task) error

ForceSeries runs the supplied tasks in series. All tasks will be run, regardless of any errors. If there is an error, it will be of type *multierror.Error.

func Forever Uses

func Forever(task Task) error

Forever runs the passed in task until it returns an error. If it never returns an error, it will be run indefinitely.

func Parallel Uses

func Parallel(tasks ...Task) error

Parallel runs the supplied tasks in parallel. The function returns once all tasks have been run. If there is an error, it will be of type *multierror.Error.

func ParallelLimit Uses

func ParallelLimit(limit int, tasks ...Task) error

ParallelLimit runs the supplied tasks in parallel. The function returns once all tasks have been run. If there is an error, it will be of type *multierror.Error.

func Race Uses

func Race(tasks ...Task) error

Race runs the supplied tasks at the same time. If any of the tasks returns an error, the error will be returned and subsequent errors of the remaining tasks will be ignored. Equivalent to Promise.race.

func Retry Uses

func Retry(task Task, max int) error

Retry runs the passed in task until it succeeds, but a total maximum of max times. In case of constantly failing tasks, the last returned error will be returned.

func Series Uses

func Series(tasks ...Task) error

Series runs the supplied tasks in series. If a task returns an error, the remaining tasks won't be run and the error returned.

func Timeout Uses

func Timeout(t Task, limit time.Duration) error

Timeout sets a time limit on an asynchronous task. If the task takes longer than the specified duration, an error of type TimeoutError will be returned.

func Times Uses

func Times(n int, task Task) error

Times runs the passed in task n times. If the task returns an error, the execution will be stopped and the error returned.

func Until Uses

func Until(test Test, task Task) error

Until is the inverse of While. It runs the specified task until it returns true or the task fails. If the task returns an error, the execution will be stopped and the error returned.

func Whilst Uses

func Whilst(test Test, task Task) error

Whilst repeatedly runs the task as long as test returns true and the task succeeds. If the task returns an error, the execution will be stopped and the error returned.

type InvalidLimitError Uses

type InvalidLimitError struct {
    Limit int
}

InvalidLimitError represents a runtime error that occurs when passing an invalid limit to ParallelLimit.

func (*InvalidLimitError) Error Uses

func (e *InvalidLimitError) Error() string

Error returns an error string.

type Semaphore Uses

type Semaphore chan empty

Semaphore implements a semaphore using an empty channel with specified buffer size.

func NewSemaphore Uses

func NewSemaphore(n int) Semaphore

NewSemaphore creates a new semaphore of the specified capacity.

func (Semaphore) Down Uses

func (s Semaphore) Down(n int)

Down releases n resources.

func (Semaphore) Up Uses

func (s Semaphore) Up(n int)

Up acquires n resources.

type Task Uses

type Task interface {
    // Run synchronously executes the task.
    // In order to simulate multiple return values while guaranteeing
    // type-safety, amend the interface with additional properties.
    Run() error
}

Task represents a job that can be run. You are encouraged to amend this interface accordingly in order to reference results of the task.

func Wrap Uses

func Wrap(run func() error) Task

Wrap creates a new task from a run function. This is useful in case you want to wrap an arbitrary function into a task.

type Test Uses

type Test func() bool

Test is a truth test that will be performed before each execution of the underlying task.

func (Test) Negate Uses

func (t Test) Negate() Test

Negate returns the inverse of the underlying test function. If the test returns true, Negate would return false and vice-versa.

type TimeoutError Uses

type TimeoutError struct {
    Limit time.Duration
}

TimeoutError is a description of a timeout error that will be returned once a specified time duration has been exceeded.

func (*TimeoutError) Error Uses

func (e *TimeoutError) Error() string

Error returns an error string.

type TimeoutTask Uses

type TimeoutTask struct {
    // Limit is the duration that the task is allowed to take.
    Limit time.Duration
}

TimeoutTask represents a task that will return a TimeoutError once a specified time limit has been exceeded.

func (*TimeoutTask) Run Uses

func (t *TimeoutTask) Run() error

Run starts the execution of the task and returns an error once the time limit has passed.

Package taker imports 4 packages (graph). Updated 2016-11-16. Refresh now. Tools for package owners.