requests

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsensusRequest

type ConsensusRequest[T any, R ConsensusResponse] interface {
	ID() string
	Copy() T
	ExpiryTime() time.Time
	SendResponse(ctx context.Context, response R)
	SendTimeout(ctx context.Context)
}

type ConsensusResponse

type ConsensusResponse interface {
	RequestID() string
}

type Handler

type Handler[T ConsensusRequest[T, R], R ConsensusResponse] struct {
	services.Service
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler[T ConsensusRequest[T, R], R ConsensusResponse](lggr logger.Logger, s *Store[T], clock clockwork.Clock, responseExpiryTime time.Duration) *Handler[T, R]

func (*Handler[T, R]) SendRequest

func (h *Handler[T, R]) SendRequest(ctx context.Context, r T)

func (*Handler[T, R]) SendResponse

func (h *Handler[T, R]) SendResponse(ctx context.Context, resp R)

type Store

type Store[T StoredRequest[T]] struct {
	// contains filtered or unexported fields
}

Store is a generic store for ongoing consensus requests. It is thread-safe and uses a map to store requests.

func NewStore

func NewStore[T StoredRequest[T]]() *Store[T]

func NewStoreWithStatsCollector added in v0.9.0

func NewStoreWithStatsCollector[T StoredRequest[T]](statsCollector statsCollector) *Store[T]

func (*Store[T]) Add

func (s *Store[T]) Add(req T) error

Add adds a new request to the store.

func (*Store[T]) Evict

func (s *Store[T]) Evict(requestID string) (T, bool)

Evict removes a request from the store by its ID.

func (*Store[T]) FirstN

func (s *Store[T]) FirstN(batchSize int) ([]T, error)

FirstN retrieves up to `batchSize` requests. The method deep-copies requests before returning them.

func (*Store[T]) Get

func (s *Store[T]) Get(requestID string) T

Get retrieves a request by its ID. The method deep-copies the request before returning it.

func (*Store[T]) GetByIDs

func (s *Store[T]) GetByIDs(requestIDs []string) []T

GetByIDs retrieves requests by their IDs. The method deep-copies requests before returning them.

func (*Store[T]) Len

func (s *Store[T]) Len() int

func (*Store[T]) RangeN

func (s *Store[T]) RangeN(start, batchSize int) ([]T, error)

RangeN retrieves up to `batchSize` requests starting at index `start`. It deep-copies each request before returning.

type StoredRequest

type StoredRequest[T any] interface {
	ID() string
	Copy() T
}

Jump to

Keyboard shortcuts

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