Documentation ¶
Index ¶
- func DoWhilst(task Task, test Test) error
- func ForceSeries(tasks ...Task) error
- func Forever(task Task) error
- func Parallel(tasks ...Task) error
- func ParallelLimit(limit int, tasks ...Task) error
- func Race(tasks ...Task) error
- func Retry(task Task, max int) error
- func Series(tasks ...Task) error
- func Timeout(t Task, limit time.Duration) error
- func Times(n int, task Task) error
- func Until(test Test, task Task) error
- func Whilst(test Test, task Task) error
- type InvalidLimitError
- type Semaphore
- type Task
- type Test
- type TimeoutError
- type TimeoutTask
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoWhilst ¶
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 ¶
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 ¶
Forever runs the passed in task until it returns an error. If it never returns an error, it will be run indefinitely.
func Parallel ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Times runs the passed in task n times. If the task returns an error, the execution will be stopped and the error returned.
Types ¶
type InvalidLimitError ¶
type InvalidLimitError struct {
Limit int
}
InvalidLimitError represents a runtime error that occurs when passing an invalid limit to ParallelLimit.
func (*InvalidLimitError) Error ¶
func (e *InvalidLimitError) Error() string
Error returns an error string.
type Semaphore ¶
type Semaphore chan empty
Semaphore implements a semaphore using an empty channel with specified buffer size.
func NewSemaphore ¶
NewSemaphore creates a new semaphore of the specified capacity.
type Task ¶
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.
type Test ¶
type Test func() bool
Test is a truth test that will be performed before each execution of the underlying task.
type TimeoutError ¶
TimeoutError is a description of a timeout error that will be returned once a specified time duration has been exceeded.
type TimeoutTask ¶
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 ¶
func (t *TimeoutTask) Run() error
Run starts the execution of the task and returns an error once the time limit has passed.