async

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FutureFunc

type FutureFunc[T any] func(ctx context.Context) (T, error)

type FutureGroup

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

FutureGroup is a container that collect execution result from multiple jobs.

func NewGroup

func NewGroup[T any]() *FutureGroup[T]

NewGroup create a FutureGroup

func (*FutureGroup[T]) Go

func (rg *FutureGroup[T]) Go(job FutureFunc[T])

Go registers a job that produce a T on success.

The job is called with a context, which is cancelled automatically if some other job return error.

func (*FutureGroup[T]) Wait

func (rg *FutureGroup[T]) Wait(ctx context.Context) ([]T, error)

Wait blocks wait until all jobs complete, returns results and the first error (if any).

Just like sync.WaitGroup and errgroup.Group, caller should Add/Launch job and Wait in the same goroutine.

Jump to

Keyboard shortcuts

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