Documentation
¶
Index ¶
- func ContextFromChan(chStop <-chan struct{}) (context.Context, context.CancelFunc)
- func WithJitter(d time.Duration) time.Duration
- type Duration
- func (d Duration) Duration() time.Duration
- func (d Duration) MarshalJSON() ([]byte, error)
- func (d Duration) MarshalText() ([]byte, error)
- func (d *Duration) Scan(v interface{}) (err error)
- func (d Duration) String() string
- func (d *Duration) UnmarshalJSON(input []byte) error
- func (d *Duration) UnmarshalText(input []byte) error
- func (d Duration) Value() (driver.Value, error)
- type StartStopOnce
- func (s *StartStopOnce) Healthy() error
- func (s *StartStopOnce) IfNotStopped(f func()) (ok bool)
- func (s *StartStopOnce) IfStarted(f func()) (ok bool)
- func (s *StartStopOnce) Ready() error
- func (s *StartStopOnce) StartOnce(name string, fn func() error) error
- func (s *StartStopOnce) State() startStopOnceState
- func (s *StartStopOnce) StopOnce(name string, fn func() error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextFromChan ¶
func ContextFromChan(chStop <-chan struct{}) (context.Context, context.CancelFunc)
ContextFromChan creates a context that finishes when the provided channel receives or is closed. When channel closes, the ctx.Err() will always be context.Canceled NOTE: Spins up a goroutine that exits on cancellation. REMEMBER TO CALL CANCEL OTHERWISE IT CAN LEAD TO MEMORY LEAKS
Types ¶
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration is a non-negative time duration.
func (Duration) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Duration) MarshalText ¶
MarshalText implements the text.Marshaler interface.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Duration) UnmarshalText ¶
UnmarshalText implements the text.Unmarshaler interface.
type StartStopOnce ¶
type StartStopOnce struct {
sync.RWMutex // lock is held during startup/shutdown, RLock is held while executing functions dependent on a particular state
// contains filtered or unexported fields
}
StartStopOnce can be embedded in a struct to help implement types.Service.
func (*StartStopOnce) Healthy ¶
func (s *StartStopOnce) Healthy() error
Healthy returns ErrNotStarted if the state is not started. Override this per-service with more specific implementations.
func (*StartStopOnce) IfNotStopped ¶
func (s *StartStopOnce) IfNotStopped(f func()) (ok bool)
IfNotStopped runs the func and returns true if in any state other than Stopped
func (*StartStopOnce) IfStarted ¶
func (s *StartStopOnce) IfStarted(f func()) (ok bool)
IfStarted runs the func and returns true only if started, otherwise returns false
func (*StartStopOnce) Ready ¶
func (s *StartStopOnce) Ready() error
Ready returns ErrNotStarted if the state is not started.
func (*StartStopOnce) StartOnce ¶
func (s *StartStopOnce) StartOnce(name string, fn func() error) error
StartOnce sets the state to Started
func (*StartStopOnce) State ¶
func (s *StartStopOnce) State() startStopOnceState
State retrieves the current state