service

package
v0.0.0-...-5d3badf Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parallel

func Parallel(main func(ParallelScope) error) error

Parallel executes a function in parallel scope. Compared to Run, it does not allow for early cancellation, therefore is suitable for non-blocking computations. Returns the first error returned by any of the spawned tasks. Waits until all the tasks complete, before returning.

func Run

func Run(ctx context.Context, main func(context.Context, Scope) error) error

Run runs a scope capable of spawning tasks. It is guaranteed that all the spawned tasks will be executed (even if spawned after the context is cancelled), and that `Run` will return only after all the tasks have completed. Context of the tasks will be automatically cancelled as soon as ANY task returns an error. Returns the first error returned by any task (main or background).

func Run1

func Run1[R any](ctx context.Context, main func(context.Context, Scope) (R, error)) (res R, err error)

Run1 is the same as Run, but returns the result of the main task.

Types

type JoinHandle

type JoinHandle[R any] struct {
	// contains filtered or unexported fields
}

JoinHandle is a handle to an awaitable task.

func Spawn1

func Spawn1[R any](s Scope, t func() (R, error)) JoinHandle[R]

Spawn1 is the same as Scope.Spawn, but allows awaiting completion of a task and getting its result.

func (JoinHandle[R]) Join

func (h JoinHandle[R]) Join(ctx context.Context) (R, error)

Join awaits completion of a task and returns its result. WARNING: it does NOT return the error of the task - error is returned from the Run() command. Join() can only fail when context is canceled.

type ParallelScope

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

ParallelScope is a scope which doesn't require cancellation token, just parallelization.

func (ParallelScope) Spawn

func (s ParallelScope) Spawn(t func() error)

Spawn spawns a new task in the scope.

type Scope

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

Scope of concurrenct tasks.

func (Scope) Spawn

func (s Scope) Spawn(t func() error)

Spawn spawns a main task. Scope gets automatically canceled when all the main tasks return.

func (Scope) SpawnBg

func (s Scope) SpawnBg(t func() error)

SpawnBg spawns a background task. Background tasks get canceled when all the main tasks return.

func (Scope) SpawnBgNamed

func (s Scope) SpawnBgNamed(name string, t func() error)

SpawnBgNamed spawns a named background task.

func (Scope) SpawnNamed

func (s Scope) SpawnNamed(name string, t func() error)

SpawnNamed spawns a named main task.

Jump to

Keyboard shortcuts

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