Documentation ¶
Index ¶
- Variables
- type Shutter
- func (s *Shutter) Err() error
- func (s *Shutter) IsTerminated() bool
- func (s *Shutter) IsTerminating() bool
- func (s *Shutter) LockedInit(fn func() error) (err error)
- func (s *Shutter) OnShutdown(f func(error))
- func (s *Shutter) Shutdown(err error)
- func (s *Shutter) Terminated() <-chan struct{}
- func (s *Shutter) Terminating() <-chan struct{}
Constants ¶
This section is empty.
Variables ¶
var ErrShutterWasAlreadyDown = errors.New("saferun was called on an already-shutdown shutter")
Functions ¶
This section is empty.
Types ¶
type Shutter ¶
type Shutter struct {
// contains filtered or unexported fields
}
func NewWithCallback ¶ added in v1.1.3
func (*Shutter) IsTerminated ¶ added in v1.3.0
func (*Shutter) IsTerminating ¶ added in v1.3.0
func (*Shutter) LockedInit ¶ added in v1.2.0
LockedInit allows you to run a function only if the shutter is not down yet, with the assurance that the it will not run its callback functions during the execution of your function.
This is useful to prevent race conditions, where the func given to "LockedInit" should increase a counter and the func given to OnShutdown should decrease it.
WARNING: never call Shutdown from within your LockedInit function, it will deadlock. Also, keep these init functions as short as possible.
NOTE: This was previously named SafeRun
func (*Shutter) OnShutdown ¶ added in v1.1.3
OnShutdown registers an additional handler to be triggered on `Shutdown()`. These calls will be blocking. It is unsafe to register new callbacks in multiple go-routines.
func (*Shutter) Terminated ¶ added in v1.3.0
func (s *Shutter) Terminated() <-chan struct{}
func (*Shutter) Terminating ¶ added in v1.3.0
func (s *Shutter) Terminating() <-chan struct{}