future

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParamTypeConversionFailed = errors.New("param type conversion failed")
)

Functions

func GetAll

func GetAll[T any](futures []*Future[T]) ([]T, error)

GetAll function waits for the completion of specified futures using the WaitAll function. If any error occurs during the waiting process, it returns an error immediately. Otherwise, it extracts the results from completed futures and returns them as a slice.

Parameters:

  • futures: List of futures to wait for.

Return:

  • A slice containing the results of completed futures.
  • If any error occurs during the waiting process, it returns an error.

func GetParam added in v0.2.0

func GetParam[T any](futureParams Params, index int) (ret T, err error)

func GetResult

func GetResult[T any](f *Future[any]) T

GetResult function retrieves the result of a completed Future. It assumes that the Future has completed successfully. Note: This function may panic if the type assertion fails.

Parameters:

  • f: Future from which to retrieve the result.

Return:

  • The result of the completed Future.

func WaitAll

func WaitAll[T any](futures []*Future[T]) error

WaitAll function waits for the completion of specified futures. If any error occurs during the process, it stops waiting and returns the first error encountered.

Parameters:

  • futures: List of futures to wait for.

Return:

  • If at least one error occurs, it returns the first error encountered.
  • If there are no errors, it returns nil.

func WaitAllContinueOnError added in v0.2.0

func WaitAllContinueOnError[T any](futures []*Future[T]) []error

WaitAllContinueOnError function waits for the completion of specified futures and continues even if an error occurs during the process. It returns a list of errors that occurred.

Parameters:

  • futures: List of futures to wait for.

Return:

  • A list of errors that occurred during the execution. The list may be empty if there are no errors.

func WaitAllSilently

func WaitAllSilently[T any](futures []*Future[T])

WaitAllSilently function waits for the completion of specified futures without collecting or returning any error information. It performs a silent wait using a sync.WaitGroup to wait for all futures to complete.

Parameters:

  • futures: List of futures to wait for.

func WaitFor

func WaitFor(futures ...*Future[any]) error

WaitFor function is a convenience wrapper around the WaitAll function. It waits for the completion of specified futures and returns an error if any of the futures encounters an error.

Parameters:

  • futures: Variadic parameter representing a list of futures to wait for.

Return:

  • If any error occurs during the waiting process, it returns an error.

func WaitForContinueOnError added in v0.2.0

func WaitForContinueOnError(futures ...*Future[any]) []error

WaitForContinueOnError function is a convenience wrapper around the WaitAllContinueOnError function. It waits for the completion of specified futures and continues even if an error occurs during the process. It returns a list of errors that occurred during the execution.

Parameters:

  • futures: Variadic parameter representing a list of futures to wait for.

Return:

  • A list of errors that occurred during the execution. The list may be empty if there are no errors.

Types

type Future

type Future[T any] struct {
	Result T
	Err    error
	IsDone bool
	// contains filtered or unexported fields
}

func Run

func Run[T any](f func() (T, error)) *Future[T]

func RunWithParam added in v0.2.0

func RunWithParam[T any, P any](f func(P) (T, error), param P) *Future[T]

func (*Future[T]) Get

func (f *Future[T]) Get() (T, error)

func (*Future[T]) GetResult

func (f *Future[T]) GetResult() T

func (*Future[T]) Wait

func (f *Future[T]) Wait()

type Group added in v0.3.0

type Group[T any] struct {
	// contains filtered or unexported fields
}

func (*Group[T]) Get added in v0.3.0

func (g *Group[T]) Get() ([]T, error)

func (*Group[T]) GetFutures added in v0.3.0

func (g *Group[T]) GetFutures() []*Future[T]

func (*Group[T]) Go added in v0.3.0

func (g *Group[T]) Go(f func() (T, error)) *Future[T]

func (*Group[T]) GoWithParams added in v0.3.0

func (g *Group[T]) GoWithParams(f func(params Params) (T, error), param Params) *Future[T]

func (*Group[T]) Wait added in v0.3.0

func (g *Group[T]) Wait() error

func (*Group[T]) WaitContinueOnError added in v0.3.0

func (g *Group[T]) WaitContinueOnError() []error

type Params added in v0.2.0

type Params []any

func (Params) GetBoolParam added in v0.2.2

func (p Params) GetBoolParam(index int) bool

func (Params) GetBytesParam added in v0.2.2

func (p Params) GetBytesParam(index int) []byte

func (Params) GetFloat32Param added in v0.2.2

func (p Params) GetFloat32Param(index int) float32

func (Params) GetFloat64Param added in v0.2.2

func (p Params) GetFloat64Param(index int) float64

func (Params) GetInt32Param added in v0.2.2

func (p Params) GetInt32Param(index int) int32

func (Params) GetInt64Param added in v0.2.2

func (p Params) GetInt64Param(index int) int64

func (Params) GetIntParam added in v0.2.2

func (p Params) GetIntParam(index int) int

func (Params) GetStringParam added in v0.2.2

func (p Params) GetStringParam(index int) string

func (Params) GetUInt8Param added in v0.2.2

func (p Params) GetUInt8Param(index int) uint8

func (Params) GetUInt32Param added in v0.2.2

func (p Params) GetUInt32Param(index int) uint32

func (Params) GetUInt64Param added in v0.2.2

func (p Params) GetUInt64Param(index int) uint64

func (Params) GetUIntParam added in v0.2.2

func (p Params) GetUIntParam(index int) uint

Jump to

Keyboard shortcuts

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