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 ¶
SharedComponent ensures that the wrapped component is started and stopped only once. When stopped it is removed from the SharedComponents map.
func (*SharedComponent[V]) Shutdown ¶
func (r *SharedComponent[V]) Shutdown(ctx context.Context) error
Shutdown implements component.Component.
func (*SharedComponent[V]) Unwrap ¶
func (r *SharedComponent[V]) Unwrap() V
Unwrap returns the original component.
type SharedComponents ¶
type SharedComponents[K comparable, V component.Component] 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[K comparable, V component.Component]() *SharedComponents[K, V]
NewSharedComponents returns a new empty SharedComponents.
func (*SharedComponents[K, V]) GetOrAdd ¶
func (scs *SharedComponents[K, V]) GetOrAdd(key K, create func() (V, error)) (*SharedComponent[V], error)
GetOrAdd returns the already created instance if exists, otherwise creates a new instance and adds it to the map of references.