sharedcomponent

package
v0.98.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package sharedcomponent exposes functionality for components to register against a shared key, such as a configuration object, in order to be reused across signal types. This is particularly useful when the component relies on a shared resource such as os.File or http.Server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component added in v0.92.0

type Component[V component.Component] struct {
	// contains filtered or unexported fields
}

Component ensures that the wrapped component is started and stopped only once. When stopped it is removed from the Map.

func (*Component[V]) Shutdown added in v0.92.0

func (c *Component[V]) Shutdown(ctx context.Context) error

Shutdown shuts down the underlying component.

func (*Component[V]) Start added in v0.92.0

func (c *Component[V]) Start(ctx context.Context, host component.Host) error

Start starts the underlying component if it never started before.

func (*Component[V]) Unwrap added in v0.92.0

func (c *Component[V]) Unwrap() V

Unwrap returns the original component.

type Map added in v0.92.0

type Map[K comparable, V component.Component] struct {
	// contains filtered or unexported fields
}

Map keeps reference of all created instances for a given shared key such as a component configuration.

func NewMap added in v0.92.0

func NewMap[K comparable, V component.Component]() *Map[K, V]

func (*Map[K, V]) LoadOrStore added in v0.92.0

func (m *Map[K, V]) LoadOrStore(key K, create func() (V, error), telemetrySettings *component.TelemetrySettings) (*Component[V], error)

LoadOrStore returns the already created instance if exists, otherwise creates a new instance and adds it to the map of references.

Jump to

Keyboard shortcuts

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