Documentation ¶
Overview ¶
Package sharedcomponent exposes util functionality for receivers and exporters that need to share state between different signal types instances such as net.Listener or os.File.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SharedComponent ¶
type SharedComponent struct { // contains filtered or unexported fields }
SharedComponent ensures that the wrapped component is started and stopped only once. When stopped it is removed from the SharedComponents map.
func (*SharedComponent) Shutdown ¶
func (r *SharedComponent) Shutdown(ctx context.Context) error
Shutdown implements component.Component.
func (*SharedComponent) Unwrap ¶
func (r *SharedComponent) Unwrap() component.Component
Unwrap returns the original component.
type SharedComponents ¶
type SharedComponents struct {
// contains filtered or unexported fields
}
SharedComponents a map that keeps reference of all created instances for a given configuration, and ensures that the shared state is started and stopped only once.
func NewSharedComponents ¶
func NewSharedComponents() *SharedComponents
NewSharedComponents returns a new empty SharedComponents.
func (*SharedComponents) GetOrAdd ¶
func (scs *SharedComponents) GetOrAdd(key interface{}, create func() component.Component) *SharedComponent
GetOrAdd returns the already created instance if exists, otherwise creates a new instance and adds it to the map of references.