service

package
v0.0.0-...-5a53b6d Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector[T any] func(ctx context.Context) (T, error)

Connector represents a function that attempts to connect to a service

type Service

type Service[T any] struct {
	// contains filtered or unexported fields
}

Service wraps a connection to an external service with reconnection capabilities

func New

func New[T any](name string, connector Connector[T]) *Service[T]

New creates a new service wrapper

func (*Service[T]) Connect

func (s *Service[T]) Connect(ctx context.Context) (T, error)

Connect attempts to connect to the service, retrying every 500ms for 3 seconds

func (*Service[T]) ConnectedChan

func (s *Service[T]) ConnectedChan() <-chan bool

func (*Service[T]) Get

func (s *Service[T]) Get(ctx context.Context) (T, error)

Get returns the current client, attempting to connect if not connected

func (*Service[T]) IsConnected

func (s *Service[T]) IsConnected() bool

IsConnected returns whether the service is currently connected

func (*Service[T]) StartReconnectLoop

func (s *Service[T]) StartReconnectLoop(ctx context.Context)

StartReconnectLoop starts a goroutine that attempts to connect periodically, to check whether the service is still available.

Jump to

Keyboard shortcuts

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