Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Future ¶
type Future[T any] struct { // contains filtered or unexported fields }
Future provides a way to easily start a go routine and get the result of the go routine later. Avoid building any mapping functionality into futures, as that can make them difficult to reason about
func SubmitFuture ¶
func SubmitFuture[T any](ctx context.Context, runner GoroutineRunner, fn func() (T, error)) (Future[T], error)
SubmitFuture creates a new future that will run the given function in a go routine.
This function will potentially block depending on the underlying GoroutineRunner implementation. E.g., the GoroutineRunner could be a worker pool with a limited number of workers, in which case this function could block until a worker is available.
type GoroutineRunner ¶
type GoroutineRunner interface { // Go starts a go routine and returns an error if the go routine could not be started. Go(context.Context, func()) error }
Future provides a way to easily start a go routine and get the result of the go routine later. Avoid building any mapping functionality into futures, as that can make them difficult to reason about
func NewSynchronousGoroutineRunner ¶
func NewSynchronousGoroutineRunner() GoroutineRunner
NewSynchronousGoroutineRunner creates a new goroutine runner that runs the goroutines synchronously
type LimitedGoroutineRunner ¶
type LimitedGoroutineRunner struct {
// contains filtered or unexported fields
}
func NewGoroutineLimiter ¶
func NewGoroutineLimiter(limit int64) *LimitedGoroutineRunner
NewGoroutineLimiter creates a new GoroutineRunner that limits the number of goroutines. No more than the limit number of goroutines can be running at the same time.
type SynchronousGoroutineRunner ¶
type SynchronousGoroutineRunner struct{}