stream

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

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

type ReaderFactory func(context.Context, string) (io.Reader, error)

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.

Jump to

Keyboard shortcuts

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