Documentation ¶
Overview ¶
package lifetime provides common component lifetime control logic.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NotStopped ¶
Types ¶
type BiState ¶
type BiState int32
BiState provides pre-defined simple binary state - normal or closed.
type CheckHealth ¶
CheckHealth function type for lifetime healthy check.
type Lifetime ¶
type Lifetime[T any] interface { SafeChan // SetState is the method to change lifetime state. SetState(state T) // GetState returns current state. GetState() T // Add records a task is running, returns false if the lifetime is not healthy. Add(isHealthy CheckHealth[T]) error // Done records a task is done. Done() // Wait waits until all tasks are done. Wait() }
Lifetime interface for lifetime control.
func NewLifetime ¶
NewLifetime returns a new instance of Lifetime with init state and isHealthy logic.
type SafeChan ¶
type SafeChan interface { IsClosed() bool CloseCh() <-chan struct{} Close() }
SafeChan is the utility type combining chan struct{} & sync.Once. It provides double close protection internally.
func NewSafeChan ¶
func NewSafeChan() SafeChan
NewSafeChan returns a SafeChan with internal channel initialized
Click to show internal directories.
Click to hide internal directories.