lifecycle

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: MIT Imports: 2 Imported by: 24

README

go-lifecycle GoDoc Build Status

Lifecycle utility for goroutine-based objects.

See here for a complete example.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRunning = errors.New("lifecycle: still running")

Functions

This section is empty.

Types

type Lifecycle

type Lifecycle interface {
	LifecycleReader

	// ShutdownRequest() returns a channel that is available for reading when
	// a shutdown has requested.
	ShutdownRequest() <-chan error

	// ShutdownInitiated() declares that shutdown has begun.  Will panic if called twice.
	ShutdownInitiated(error)

	// ShutdownCompleted() declares that shutdown has completed.  Will panic if called twice.
	ShutdownCompleted()

	// WatchContext() observes the given context and initiates a shutdown
	// if the context is shutdown before the lifecycle is.
	WatchContext(context.Context)

	// Begins shutdown when given channel is ready for reading.
	WatchChannel(<-chan struct{})

	// Shutdown() initiates shutdown by sending a value to the channel
	// requtned by ShutdownRequest() and blocks untill ShutdownCompleted()
	// is called.
	Shutdown(error)

	// Initiate shutdown but does not block until complete.
	ShutdownAsync(error)
}

func New

func New() Lifecycle

type LifecycleReader

type LifecycleReader interface {
	// ShuttingDown() returns a channel that is available for reading
	// after ShutdownInitiated() has been called.
	ShuttingDown() <-chan struct{}

	// Done() returns a channel that is available for reading
	// after ShutdownCompleted() has been called.
	Done() <-chan struct{}

	Error() error
}

LifecycleReader exposes read-only access to lifecycle state.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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