Documentation ¶
Index ¶
- Constants
- func Add_signals(end Line_end, sig ...os.Signal) option
- func With_cancel(parent *Group) option
- func With_cancel_nowait(ctx context.Context) option
- func With_timeout(parent *Group, timeout time.Duration) option
- func With_timeout_nowait(ctx context.Context, timeout time.Duration) option
- type Group
- type Grouper
- type Line_end
Constants ¶
const ( None Line_end = `` Unix = "\n" Osx = "\r" Windows = "\r\n" Backspace = "\b\b" )
Variables ¶
This section is empty.
Functions ¶
func Add_signals ¶
Add_signals will call Group.Cancel() when a signal is received. Interrupted will be set to true. An "end" character will be output to os.Stderr upon receiving a signal. if sig is absent, os.Interrupt and syscall.SIGTERM will be used.
func With_cancel ¶
func With_cancel(parent *Group) option
Use WithCancel() as the context to New(). Will panic if context is already set. Will panic if parent is nil. Register/Unregister use the parent's WaitGroup.
func With_cancel_nowait ¶
Use WithCancel() as the context to New(). If ctx is a *gogroup.Group, the parent will not Wait(). Use With_cancel_wait() to have a parent gogroup.Group wait on a child gogroup.Group.
func With_timeout ¶
Will panic if gg is nil or context is already set.
Types ¶
type Group ¶
type Group struct { context.Context context.CancelFunc Interrupted bool // contains filtered or unexported fields }
A Group is a collection of goroutines working on subtasks that are part of the same overall task.
func New ¶
func New(opt ...option) *Group
New returns a Group using with zero or more options. If a context is not provided in an option, With_cancel() will be used. The Group.Context is canceled when either a Go() func returns or a func using Register()/Unregister(). New must be called to make a Group.
func (*Group) Go ¶
Go calls the given function in a new goroutine. The first call to return cancels the group. A Grouper should receive on Group.Ctx.Done() to gracefully end.
func (*Group) Register ¶
Register increments the internal sync.WaitGroup. Unregister() must be called with the returned int to end Group.Wait(). goroutines using Register/Unregister should end upon receipt from the Group.Ctx.Done() channel.
func (*Group) Unregister ¶
Unregister decrements the internal sync.WaitGroup and called Group.Cancel(). It is safe to call Unregister multiple times.