await

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 4 Imported by: 4

Documentation

Overview

Package await contains await helper functions for use with tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(awaitables ...*task.Task) ([]interface{}, error)

All will wait for every given task to emit a result, the results (& errors) will be returned in a slice ordered the same as the input.

func AllAsync added in v2.1.0

func AllAsync(awaitables ...*task.Task) *task.Task

AllAsync does the same thing as All but does so asynchronously

func AllOrError

func AllOrError(awaitables ...*task.Task) ([]interface{}, error)

AllOrError will wait for every given task to emit a result or return as soon as an error is encountered, stopping all other tasks.

func AllOrErrorAsync added in v2.1.0

func AllOrErrorAsync(awaitables ...*task.Task) *task.Task

AllOrErrorAsync does the same thing as AllOrError but does so asynchronously

func AllOrErrorWithTimeout

func AllOrErrorWithTimeout(timeout time.Duration, awaitables ...*task.Task) ([]interface{}, error)

AllOrErrorWithTimeout does the same as AllOrError but allows you to set a timeout for waiting for other tasks to stop.

func AllOrErrorWithTimeoutAsync added in v2.1.0

func AllOrErrorWithTimeoutAsync(timeout time.Duration, awaitables ...*task.Task) *task.Task

AllOrErrorWithTimeoutAsync does the same thing as AllOrErrorWithTimeout but does so asynchronously

func Any

func Any(awaitables ...*task.Task) (interface{}, error)

Any will wait for the first task to emit a result (or an error) and return that, stopping all other tasks.

func AnyAsync added in v2.1.0

func AnyAsync(awaitables ...*task.Task) *task.Task

AnyAsync does the same thing as Any but does so asynchronously

func AnyWithTimeout

func AnyWithTimeout(timeout time.Duration, awaitables ...*task.Task) (interface{}, error)

AnyWithTimeout does the same as Any but allows you to set a timeout for waiting for other tasks to stop.

func AnyWithTimeoutAsync added in v2.1.0

func AnyWithTimeoutAsync(timeout time.Duration, awaitables ...*task.Task) *task.Task

AnyWithTimeoutAsync does the same thing as AnyWithTimeout but does so asynchronously

func FastAllOrError

func FastAllOrError(awaitables ...*task.Task) ([]interface{}, error)

FastAllOrError does the same as AllOrError but does not wait for all other tasks to stop, it does tell them to stop it just doesn't wait for them to stop.

func FastAllOrErrorAsync added in v2.1.0

func FastAllOrErrorAsync(awaitables ...*task.Task) *task.Task

FastAllOrErrorAsync does the same thing as FastAllOrError but does so asynchronously

func FastAny

func FastAny(awaitables ...*task.Task) (interface{}, error)

FastAny does the same as Any but does not wait for all other tasks to stop, it does tell them to stop it just doesn't wait for them to stop.

func FastAnyAsync added in v2.1.0

func FastAnyAsync(awaitables ...*task.Task) *task.Task

FastAnyAsync does the same thing as FastAny but does so asynchronously

func MustAll

func MustAll(awaitables ...*task.Task) []interface{}

MustAll does the same thing as All but panics if an error is encountered

func MustAllOrError

func MustAllOrError(awaitables ...*task.Task) []interface{}

MustAllOrError does the same thing as AllOrError but panics if an error is encountered

func MustAllOrErrorWithTimeout

func MustAllOrErrorWithTimeout(timeout time.Duration, awaitables ...*task.Task) []interface{}

MustAllOrErrorWithTimeout does the same thing as AllOrErrorWithTimeout but panics if an error is encountered

func MustAny

func MustAny(awaitables ...*task.Task) interface{}

MustAny does the same thing as Any but panics if an error is encountered

func MustAnyWithTimeout

func MustAnyWithTimeout(timeout time.Duration, awaitables ...*task.Task) interface{}

MustAnyWithTimeout does the same thing as AnyWithTimeout but panics if an error is encountered

func MustFastAllOrError

func MustFastAllOrError(awaitables ...*task.Task) []interface{}

MustFastAllOrError does the same thing as FastAllOrError but panics if an error is encountered

func MustFastAny

func MustFastAny(awaitables ...*task.Task) interface{}

MustFastAny does the same thing as FastAny but panics if an error is encountered

Types

type ErrTaskFailed

type ErrTaskFailed struct {
	Errors []error
}

ErrTaskFailed is returned by the All methods when at least one task returns an error.

func (*ErrTaskFailed) Error

func (e *ErrTaskFailed) Error() string

type StreamInstance added in v2.1.0

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

StreamInstance is the object that is returned by Stream

func Stream added in v2.1.0

func Stream(awaitables ...*task.Task) *StreamInstance

Stream will wait for the first task to return and continue to do that until all tasks have returned.

For example:

s := await.Stream(foo(), bar())
for s.Wait() {
	r, err := s.Result()
}

func (*StreamInstance) MustResult added in v2.1.0

func (s *StreamInstance) MustResult() interface{}

MustResult is an alias for the completed task's MustResult method.

func (*StreamInstance) Result added in v2.1.0

func (s *StreamInstance) Result() (interface{}, error)

Result is an alias for the completed task's Result method.

func (*StreamInstance) Task added in v2.1.0

func (s *StreamInstance) Task() *task.Task

Task return the completed task

func (*StreamInstance) Wait added in v2.1.0

func (s *StreamInstance) Wait() bool

Wait will return true once a task has finished & then remove that task from the list of tasks to wait for. It will return false when there are no more tasks to wait for.

Jump to

Keyboard shortcuts

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