Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Execute ¶
func Execute( ctx context.Context, pf PeerFactory, rf ReaderFactory, sink chan<- []byte, sleep func(time.Duration), ticker func(time.Duration) *time.Ticker, )
Execute creates and maintains streams of records to multiple peers. It blocks until the parent context is canceled. It's designed to be invoked once per user stream request.
Incoming records are muxed onto the provided sink chan. The sleep func is used to backoff between retries of a single peer. The ticker func is used to regularly resolve peers.
Types ¶
type PeerFactory ¶
type PeerFactory func() []string
PeerFactory should return the current set of peer addresses. Each address will be converted to an io.Reader via the ReaderFactory. The PeerFactory is periodically invoked to get the latest set of peers.
type ReaderFactory ¶
ReaderFactory converts a peer address to an io.Reader. Readers must exit with context.Canceled when the context is canceled. Other errors will cause the managing goroutine to reconstruct the reader.
func HTTPReaderFactory ¶
func HTTPReaderFactory(client *http.Client, addr2url func(string) string) ReaderFactory
HTTPReaderFactory returns a ReaderFactory that converts the addr to a URL via the addr2url function, makes a GET request via the client, and returns the response body as the reader.