module

package
v0.0.0-...-c635e59 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0, BSD-2-Clause Imports: 3 Imported by: 47

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitSimpleLifecycle

func InitSimpleLifecycle[T Module](m T, optShutdown ...func(T)) T

InitSimpleLifecycle is a helper function that sets up the default lifecycle for the given module. If no shutdown function is provided, then the default shutdown function will be used, which automatically triggers the StoppedEvent.

Note: If a more complex lifecycle is required, then it needs to be implemented manually.

func TriggerAll

func TriggerAll(event func(Module) reactive.Event, modules ...Module)

TriggerAll triggers the given event on all given modules.

func WaitAll

func WaitAll(event func(Module) reactive.Event, modules ...Module) reactive.WaitGroup[Module]

WaitAll waits until all given modules have triggered the given event.

Types

type Module

type Module interface {
	// ConstructedEvent is the getter for an Event that is triggered when the Module was constructed.
	ConstructedEvent() reactive.Event

	// InitializedEvent is the getter for an Event that is triggered when the Module was initialized.
	InitializedEvent() reactive.Event

	// ShutdownEvent is the getter for an Event that is triggered when the Module begins its shutdown process.
	ShutdownEvent() reactive.Event

	// StoppedEvent is the getter for an Event that is triggered when the Module finishes its shutdown process.
	StoppedEvent() reactive.Event

	// NewSubModule creates a new reactive submodule with the given name.
	NewSubModule(name string) Module

	// Logger is the logger of the Module.
	log.Logger
}

Module is a trait that exposes logging and lifecycle related API capabilities, that can be used to create a modular architecture where different modules can listen and wait for each other to reach certain states.

func New

func New(logger log.Logger) Module

New creates a new Module with the given logger.

func NewTestModule

func NewTestModule(t *testing.T) Module

NewTestModule creates a new pre-configured Module for testing purposes.

type Provider

type Provider[ContainerType any, ModuleType Module] func(ContainerType) ModuleType

Provider is a function that returns a Module.

func Provide

func Provide[ContainerType any, ModuleType Module](constructor func(ContainerType) ModuleType) Provider[ContainerType, ModuleType]

Provide turns a constructor into a provider.

Jump to

Keyboard shortcuts

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