lifecycle

package
Version: v0.0.0-...-a69e935 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 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 LifeCycle

type LifeCycle interface {
	// Start is idempotent
	// No action would be performed if Start is called twice without calling Stop
	// return false if already started
	Start() bool
	// Stop is idempotent
	// No action would be performed if Stop is called twice without calling Start
	// return false if already stopped
	Stop() bool
	// StopComplete should be called by user when the stop action terminates
	// (e.g. clean up is finished, all the goroutine has exited)
	// It would unblock Wait()
	StopComplete()
	// StopCh would broadcast the Stop message when Stop is called
	StopCh() <-chan struct{}
	// Wait() would block until StopComplete is called
	Wait()
}

LifeCycle manages the lifecycle for the owner of the object example:

lifeCycle LifeCycle
lifeCycle.Start()
go func() {
	select {
	case <-lifeCycle.StopCh():
		lifeCycle.StopComplete()
		return
	}
}()
lifeCycle.Stop() // block until the goroutine returns

func NewLifeCycle

func NewLifeCycle() LifeCycle

NewLifeCycle creates a new LifeCycle instance

Source Files

Jump to

Keyboard shortcuts

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