sharedcomponent

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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