producer

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Limit

func Limit(ctx context.Context, perSecond float64, in <-chan string) <-chan string

Limit limits the number of values per second to the value perSecond. A new goroutine is started, which terminates when in is closed or the context is cancelled.

func Ranges

func Ranges(ctx context.Context, ranges []Range, format string, ch chan<- string, count chan<- int) error

Ranges sends all range values to the channel ch, and the number of items to the channel count. Sending stops and ch and count are closed when an error occurs or the context is cancelled. When format is the empty string, "%d% is used.

func Reader

func Reader(ctx context.Context, rd io.ReadCloser, ch chan<- string, count chan<- int) (err error)

Reader sends all lines read from reader channel ch, and the number of items to the channel count. Sending stops and ch and count are closed when an error occurs or the context is cancelled. The reader is closed when this function returns.

Types

type Filter

type Filter interface {
	// Count corrects the number of total items to test
	Count(ctx context.Context, in <-chan int) <-chan int

	// Select filters the items
	Select(ctx context.Context, in <-chan string) <-chan string
}

Filter selects/rejects items received from a producer.

type FilterLimit

type FilterLimit struct {
	Max int
}

FilterLimit passes through at most Max values.

func (*FilterLimit) Count

func (f *FilterLimit) Count(ctx context.Context, in <-chan int) <-chan int

Count filters the number of values.

func (*FilterLimit) Select

func (f *FilterLimit) Select(ctx context.Context, in <-chan string) <-chan string

Select filters values sent over ch.

type FilterSkip

type FilterSkip struct {
	Skip int
}

FilterSkip skips the first n values sent over the channel.

func (*FilterSkip) Count

func (f *FilterSkip) Count(ctx context.Context, in <-chan int) <-chan int

Count filters the number of values.

func (*FilterSkip) Select

func (f *FilterSkip) Select(ctx context.Context, in <-chan string) <-chan string

Select filters values sent over ch.

type Range

type Range struct {
	First, Last int
}

Range defines a range of values which should be tested.

func ParseRange

func ParseRange(s string) (r Range, err error)

ParseRange parses a range from the string s. Valid formats are `n` and `n-m`.

func (Range) Count

func (r Range) Count() int

Count returns the number of items in the range.

Jump to

Keyboard shortcuts

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