contentconsumer

package module
v0.0.0-...-52db509 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: MIT Imports: 7 Imported by: 0

README

contentconsumer

Go Lang module - Ring Buffer based timed consumer of content

Documentation

Overview

Package contentconsumer - Consumes content from channel. (e.g.) TimedContentConsumer

Index

Constants

This section is empty.

Variables

View Source
var ErrConsumerChannelClosed error = errors.New("ChannelClosed")

ErrConsumerChannelClosed - AddChunk to closed channel

View Source
var ErrConsumerDrainedEmpty error = errors.New("EmptyBuffer")

ErrConsumerDrainedEmpty - Empty Consumer Buffer

Functions

This section is empty.

Types

type ConsumerEvent

type ConsumerEvent struct {
	ID  string
	Err error
	// contains filtered or unexported fields
}

ConsumerEvent - Events

type ConsumerEventConsumer

type ConsumerEventConsumer interface {
	//Channel - Return Channel to write to.  nil if channel is closed
	Channel() chan<- ConsumerEventPtr
	//Signal Close of channel when writing is finished
	CloseChannel()
}

ConsumerEventConsumer -

type ConsumerEventPtr

type ConsumerEventPtr *ConsumerEvent

ConsumerEventPtr - Ptr to ConsumerEvent

type TimedContent

type TimedContent struct {
	// contains filtered or unexported fields
}

TimedContent - Content with duration duration - content duration data - actual content

type TimedContentConsumer

type TimedContentConsumer struct {

	//id - User name for the TimedContentConsumer
	// used in the logging
	ID string
	//Interval to drain buffer for content worth the interval
	ConsumptionInterval time.Duration

	//downstream Consumer of content drained
	Downstream chan<- interface{}
	//downstream Consumer of events
	EventDownstream chan<- ConsumerEventPtr
	// contains filtered or unexported fields
}

TimedContentConsumer -

  • Maintains a Cache of given ConsumptionInterval
  • Channel may have more
  • Drains the Cache in fixed intervals
  • While Draining can forward data using PostDataFunc(duration, data)
  • If CacheBuffer below Min Level - calls BelowMinLevelFunc()

func NewTimedContentConsumer

func NewTimedContentConsumer(id string, interval time.Duration, slots int) *TimedContentConsumer

NewTimedContentConsumer - Create

id - User Name
interval - Duration of poll
slots - intial ring buffer size estimate content to fill
        No worries it will be doubled if required

func (*TimedContentConsumer) Channel

func (cc *TimedContentConsumer) Channel() chan<- TimedContentPtr

Channel - Returns the channel to write to

func (*TimedContentConsumer) CloseChannel

func (cc *TimedContentConsumer) CloseChannel()

CloseChannel - Close the input channel This will make the Go Routine Run exit

func (*TimedContentConsumer) DrainChunks

func (cc *TimedContentConsumer) DrainChunks(ctx context.Context, wg *sync.WaitGroup)

DrainChunks - Drain the actual content

func (*TimedContentConsumer) Run

func (cc *TimedContentConsumer) Run(wg *sync.WaitGroup)

Run - Start Consuming Content

type TimedContentPtr

type TimedContentPtr *TimedContent

TimedContentPtr - Ptr to the TimedContext

func NewTimedContent

func NewTimedContent(duration time.Duration, data interface{}) TimedContentPtr

NewTimedContent - Create new TimedContent

Jump to

Keyboard shortcuts

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