xync

package module
v0.0.0-...-1cd4bc8 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package xync provides goroutine management types and functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Supervisor

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

Supervisor handles goroutine creation and termination.

func NewSupervisor

func NewSupervisor(opts ...SupervisorOption) *Supervisor

NewSupervisor creates a fresh instance of the goroutine supervisor.

func (*Supervisor) ActiveContext

func (s *Supervisor) ActiveContext() context.Context

ActiveContext returns the context that is associated with the supervisor and is cancelled either when Stop or Close is called.

func (*Supervisor) BaseContext

func (s *Supervisor) BaseContext() context.Context

BaseContext returns the context that is associated with the supervisor and is cancelled only when Close is called.

func (*Supervisor) Close

func (s *Supervisor) Close()

Close stops all currently active/idle goroutines and ensures that all new goroutines that are created in the future are stopped as well.

func (*Supervisor) CloseAndWait

func (s *Supervisor) CloseAndWait()

CloseAndWait stops all currently active/idle goroutines, blocks until all of them exit and ensures that all new goroutines that are created in the future are stopped as well.

func (*Supervisor) Go

func (s *Supervisor) Go(fn func(context.Context))

Go executes the provided function on a new goroutine. The provided function must handle all context cancellation events and exit when required. Once closed, the supervisor passes a cancelled context to all new goroutines and their functions.

func (*Supervisor) Stop

func (s *Supervisor) Stop()

Stop stops all currently active/idle goroutines.

func (*Supervisor) StopAndWait

func (s *Supervisor) StopAndWait()

StopAndWait stops all currently active/idle goroutines and blocks until all of them exit.

func (*Supervisor) Wait

func (s *Supervisor) Wait()

Wait blocks until all active goroutines exit.

type SupervisorOption

type SupervisorOption func(*Supervisor)

SupervisorOption is used to configure the supervisor.

func WithSupervisorBaseContext

func WithSupervisorBaseContext(ctx context.Context) SupervisorOption

WithSupervisorBaseContext sets the base context that is passed to all goroutines. Note that the supervisor wraps the provided context in its own internal context that is used to cancel all goroutines.

func WithSupervisorMaxActive

func WithSupervisorMaxActive(max int64) SupervisorOption

WithSupervisorMaxActive sets the maximum number of active goroutines. When the limit is reached, all new goroutines remain idle and wait until their function is executed.

Jump to

Keyboard shortcuts

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