Version: v1.0.1-0...-828edb8 Latest Latest

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

Go to latest
Published: Jan 18, 2022 License: BSD-2-Clause Imports: 1 Imported by: 0



Package stop implements a pattern for shutting down a group of processes.



This section is empty.


View Source
var AlreadyStoppedFunc = func() Result { return AlreadyStopped }

AlreadyStoppedFunc is a Func that returns AlreadyStopped.


This section is empty.


type Channel

type Channel chan []error

Channel is used to return zero or more errors asynchronously. Call Done() once to pass errors to the Channel.

func (Channel) Done

func (ch Channel) Done(errs ...error)

Done adds zero or more errors to the Channel and closes it, indicating the caller has finished stopping. It should be called exactly once.

func (Channel) Result

func (ch Channel) Result() <-chan []error

Result converts a Channel to a Result.

type Func

type Func func() Result

Func is a function that can be used to provide a clean shutdown.

type Group

type Group struct {
	// contains filtered or unexported fields

Group is a collection of Stoppers that can be stopped all at once.

func NewGroup

func NewGroup() *Group

NewGroup allocates a new Group.

func (*Group) Add

func (cg *Group) Add(toAdd Stopper)

Add appends a Stopper to the Group.

func (*Group) AddFunc

func (cg *Group) AddFunc(toAddFunc Func)

AddFunc appends a Func to the Group.

func (*Group) Stop

func (cg *Group) Stop() Result

Stop stops all members of the Group.

Stopping will be done in a concurrent fashion. The slice of errors returned contains all errors returned by stopping the members.

type Result

type Result <-chan []error

Result is a receive-only version of Channel. Call Wait() once to receive any returned errors.

var AlreadyStopped Result

AlreadyStopped is a closed error channel to be used by Funcs when an element was already stopped.

func (Result) Wait

func (r Result) Wait() []error

Wait blocks until Done() is called on the underlying Channel and returns any errors. It should be called exactly once.

type Stopper

type Stopper interface {
	// Stop returns a channel that indicates whether the stop was
	// successful.
	// The channel can either return one error or be closed.
	// Closing the channel signals a clean shutdown.
	// Stop() should return immediately and perform the actual shutdown in a
	// separate goroutine.
	Stop() Result

Stopper is an interface that allows a clean shutdown.

Source Files

Jump to

Keyboard shortcuts

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