sharedcomponent

package module
v0.114.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 5 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

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

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

Shutdown shuts down the underlying component.

func (*Component[V]) Start

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

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

Unwrap returns the original component.

type Map

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

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

func (*Map[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, create func() (V, error)) (*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