Documentation ¶
Index ¶
Constants ¶
View Source
const DefaultGracefulShutdownPeriod = 30 * time.Second
Default graceful shutdown timeout to wait for Runnables to shutdown on collection stop.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection interface { // Add will cause the Runnable to be started when Start is called. // It is started automatically if the Collection was already started. Add(Runnable) error // Start starts all registered Runnables and blocks until the stop channel is closed. // Returns an error if there is an error starting any Runnable. Start(stop <-chan struct{}) error }
Collection is a runtime utility to manage a collection of processes and handle graceful shutdown if one of them errors at any time.
func New ¶
func New(options Options, runnables ...Runnable) Collection
New returns a new Collection for managing Runnables.
type Options ¶
type Options struct { // The logger that should be used by the Collection. // If none is set, no logging is done. Logger logr.Logger // GracefulShutdownTimeout is the duration given to Runnable to // stop before the Collection actually returns on stop. // To disable graceful shutdown, set to time.Duration(0) // To use graceful shutdown without timeout, set to a negative duration, e.g. time.Duration(-1). // If not set DefaultGracefulShutdownPeriod is used. GracefulShutdownTimeout *time.Duration }
Options are the arguments for creating a new Collection
type Runnable ¶
type Runnable interface { // Start starts running the component. The component will stop running // when the channel is closed. Start blocks until the channel is closed or // an error occurs. Start(stop <-chan struct{}) error }
Runnable allows a component to be started. It's very important that Start blocks until it's done running.
type RunnableFunc ¶
type RunnableFunc func(<-chan struct{}) error
RunnableFunc implements Runnable using a function. It's very important that the given function blocks until it's done running.
func (RunnableFunc) Start ¶
func (r RunnableFunc) Start(stop <-chan struct{}) error
Start implements Runnable
Click to show internal directories.
Click to hide internal directories.