worker

package
v0.0.0-...-e1bd909 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer interface {
	Init() error
	Do(interface{}) error
	Close()
}

type ConsumerFunc

type ConsumerFunc func(interface{}) error

type Producer

type Producer interface {
	Init() error
	Do(chan<- interface{})
	Close()
}

type ProducerFunc

type ProducerFunc func(ch chan<- interface{}, isShouldStop func() bool) // 比定义一个Interface要简洁一些

type SimpleConsumer

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

func NewSimpleConsumer

func NewSimpleConsumer(f ConsumerFunc) *SimpleConsumer

func (*SimpleConsumer) Close

func (sc *SimpleConsumer) Close()

func (*SimpleConsumer) Do

func (sc *SimpleConsumer) Do(msg interface{}) error

func (*SimpleConsumer) Init

func (sc *SimpleConsumer) Init() error

type SimpleProducer

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

func NewSimpleProducer

func NewSimpleProducer(f ProducerFunc) *SimpleProducer

func (*SimpleProducer) Close

func (sp *SimpleProducer) Close()

func (*SimpleProducer) Do

func (sp *SimpleProducer) Do(ch chan<- interface{})

func (*SimpleProducer) Init

func (sp *SimpleProducer) Init() error

func (*SimpleProducer) ShouldStop

func (sp *SimpleProducer) ShouldStop() bool

type Stats

type Stats struct {
	CntConsumed        uint64
	CntConsumedSuccess uint64
	CntConsumedFail    uint64
	TimeStart          time.Time
	TimeEnd            time.Time
}

func (*Stats) String

func (s *Stats) String() string

type Worker

type Worker struct {
	Producer    Producer
	Consumer    Consumer
	ProducerNum int
	ConsumerNum int
	ChanLength  int
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(producer Producer, consumer Consumer) *Worker

func (*Worker) LogStats

func (w *Worker) LogStats(duration time.Duration, funcs ...func())

func (*Worker) Start

func (w *Worker) Start() error

Start

func (*Worker) Stats

func (w *Worker) Stats() *Stats

func (*Worker) Stop

func (w *Worker) Stop()

Jump to

Keyboard shortcuts

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