hosting

package
v0.25.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const ShutdownTimeout = time.Second * 10

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncValue

type AsyncValue[T any] struct {
	Cond  *sync.Cond
	Value *T
	Err   error
	// contains filtered or unexported fields
}

func NewAsyncValue

func NewAsyncValue[T any]() *AsyncValue[T]

NewAsyncValue creates a new AsyncValue object with a condition variable and a mutex.

func (*AsyncValue[T]) Get

func (a *AsyncValue[T]) Get(ctx context.Context) (*T, error)

Get is a function that attempts to retrieve a value from a given context, and returns the value or an error if the context is done or an error occurs.

func (*AsyncValue[T]) Put

func (a *AsyncValue[T]) Put(value *T)

Put takes in a pointer to a value and sets it as the value of the AsyncValue, then broadcasts the change to any waiting goroutines.

func (*AsyncValue[T]) PutErr

func (a *AsyncValue[T]) PutErr(err error)

PutErr sets an error value on the AsyncValue struct and broadcasts the condition variable to notify any waiting goroutines.

type Host

type Host struct {
	// Slice of services to run. Started in order.
	Services []Service

	// LoggerValues is key-value-pairs passed to .WithValues to initialize the logger for the host.
	LoggerValues []any

	// TimeoutFunc allows you to control the timeout behavior for testing
	TimeoutFunc func()
}

Host manages the lifetimes and starting of Services.

func (*Host) Run

func (host *Host) Run(ctx context.Context, serviceErrors chan<- LifecycleMessage) error

Run starts all services in the host, waits for them to finish, and returns an error if any of them fail or if a timeout is reached.

func (*Host) RunAsync

func (host *Host) RunAsync(ctx context.Context) (<-chan error, <-chan LifecycleMessage)

RunAsync runs the host's services asynchronously and returns two channels, one for errors and one for lifecycle messages, which can be used to monitor the progress of the services.

type LifecycleMessage

type LifecycleMessage struct {
	Name string
	Err  error
}

LifecycleMessage is a message returned when a service terminates.

type Service

type Service interface {
	// Name returns the name of the service.
	Name() string

	// Run runs the service as a blocking operation.
	Run(ctx context.Context) error
}

Service is an abstraction for a long-running subsystem of the RP.

Jump to

Keyboard shortcuts

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