Documentation
¶
Index ¶
- Variables
- type Option
- 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) OnTerminated(f func(error))
- func (s *Shutter) OnTerminating(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 Option ¶
type Option = func(shutter *Shutter)
func RegisterOnTerminated ¶
registers a function to be called on terminated
func RegisterOnTerminating ¶
registers a function to be called on terminating
type Shutter ¶
type Shutter struct {
// contains filtered or unexported fields
}
func (*Shutter) IsTerminated ¶
func (*Shutter) IsTerminating ¶
func (*Shutter) LockedInit ¶
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) OnTerminated ¶
OnTerminated registers an additional handler to be triggered on `Shutdown()`. These calls will be blocking and will occur when the shutter has shutdown
func (*Shutter) OnTerminating ¶
OnTerminating registers an additional handler to be triggered on `Shutdown()`. These calls will be blocking and will occur when the shutter is in the process of shutting down.
func (*Shutter) Terminated ¶
func (s *Shutter) Terminated() <-chan struct{}
func (*Shutter) Terminating ¶
func (s *Shutter) Terminating() <-chan struct{}