idem

package module
v0.0.0-...-7a80838 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2019 License: MIT Imports: 2 Imported by: 12

README

idem.Halter

idem.Hhalter supports a common pattern for halting goroutines in Go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyClosed = fmt.Errorf("Chan already closed")

Functions

This section is empty.

Types

type Halter

type Halter struct {
	// The owning goutine should call Done.Close() as its last
	// action once it has received the ReqStop() signal.
	Done IdemCloseChan

	// Other goroutines call ReqStop.Close() in order
	// to request that the owning goroutine stop immediately.
	// The owning goroutine should select on ReqStop.Chan
	// in order to recognize shutdown requests.
	ReqStop IdemCloseChan
}

Halter helps shutdown a goroutine

func NewHalter

func NewHalter() *Halter

func (*Halter) IsDone

func (h *Halter) IsDone() bool

IsDone returns true iff h.Done has been Closed().

func (*Halter) IsStopRequested

func (h *Halter) IsStopRequested() bool

IsStopRequested returns true iff h.ReqStop has been Closed().

func (*Halter) MarkDone

func (h *Halter) MarkDone()

MarkDone closes the h.Done channel if it has not already done so. Safe for multiple goroutine access.

func (*Halter) RequestStop

func (h *Halter) RequestStop()

RequestStop closes the h.ReqStop channel if it has not already done so. Safe for multiple goroutine access.

type IdemCloseChan

type IdemCloseChan struct {
	Chan chan struct{}
	// contains filtered or unexported fields
}

IdemCloseChan can have Close() called on it multiple times, and it will only close Chan once.

func NewIdemCloseChan

func NewIdemCloseChan() *IdemCloseChan

NewIdemCloseChan makes a new IdemCloseChan.

func (*IdemCloseChan) Close

func (c *IdemCloseChan) Close() error

Close returns ErrAlreadyClosed if it has been called before. It never closes IdemClose.Chan more than once, so it is safe to ignore the returned error value. Close() is safe for concurrent access by multiple goroutines. Close returns nil on the initial call, and ErrAlreadyClosed on any subsequent call.

func (*IdemCloseChan) IsClosed

func (c *IdemCloseChan) IsClosed() bool

IsClosed tells you if Chan is already closed or not.

func (*IdemCloseChan) Reinit

func (c *IdemCloseChan) Reinit()

Reinit re-allocates the Chan, assinging a new channel and reseting the state as if brand new.

Jump to

Keyboard shortcuts

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