plug

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2017 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Leased added in v1.0.5

type Leased struct {
	Plug
	// contains filtered or unexported fields
}

leased uses a Leaser to control Start and Stop on a Plug

func NewLeased added in v1.0.5

func NewLeased(leaser Leaser) *Leased

NewLeased creates a Plug that starts when a lease is acquired and stops when it is lost.

func (*Leased) Run added in v1.0.5

func (l *Leased) Run() error

Run tries to acquire and hold a lease, invoking Start() when the lease is held and invoking Stop() when the lease is lost. If the lease was lost gracefully, nil is returned. If the lease was lost due to an error, the error is returned.

func (*Leased) Stop added in v1.0.5

func (l *Leased) Stop(err error)

Stop releases the acquired lease

type Leaser added in v1.0.5

type Leaser interface {
	// AcquireAndHold tries to acquire the lease and hold it until it expires, the lease is deleted,
	// or we observe another party take the lease. The notify channel will be sent a nil value
	// when the lease is held, and closed when the lease is lost. If an error is sent the lease
	// is also considered lost.
	AcquireAndHold(chan error)
	Release()
}

Leaser controls access to a lease

type Plug

type Plug interface {
	// Begins operation of the plug and unblocks WaitForStart().
	// May be invoked multiple times but only the first invocation has
	// an effect.
	Start()
	// Ends operation of the plug and unblocks WaitForStop()
	// May be invoked multiple times but only the first invocation has
	// an effect. Calling Stop() before Start() is undefined. An error
	// may be returned with the stop.
	Stop(err error)
	// Blocks until Start() is invoked
	WaitForStart()
	// Blocks until Stop() is invoked
	WaitForStop() error
	// Returns true if Start() has been invoked
	IsStarted() bool
}

Plug represents a synchronization primitive that holds and releases execution for other objects.

func New added in v1.0.5

func New(started bool) Plug

New returns a new plug that can begin in the Started state.

Jump to

Keyboard shortcuts

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