channel

package
v0.0.0-...-21fc7a1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 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 Channel

type Channel interface {
	// Input send value to Output channel. If channel is closed, do nothing and will not panic.
	Input(v interface{})
	// Output return a read-only native chan for consumer.
	Output() <-chan interface{}
	// Len return the count of un-consumed items.
	Len() int
	// Stats return the produced and consumed count.
	Stats() (produced uint64, consumed uint64)
	// Close closed the output chan. If channel is not closed explicitly, it will be closed when it's finalized.
	Close()
}

Channel is a safe and feature-rich alternative for Go chan struct

func New

func New(opts ...Option) Channel

New create a new channel.

type Option

type Option func(c *channel)

Option define channel Option

func WithNonBlock

func WithNonBlock() Option

WithNonBlock will set channel to non-blocking Mode. The input channel will not block for any cases.

func WithRateThrottle

func WithRateThrottle(produceRate, consumeRate int) Option

WithRateThrottle is a helper function to control producer and consumer process rate. produceRate and consumeRate mean how many item could be processed in one second, aka TPS.

func WithSize

func WithSize(size int) Option

WithSize define the size of channel. If channel is full, it will block. It conflicts with WithNonBlock option.

func WithThrottle

func WithThrottle(producerThrottle, consumerThrottle Throttle) Option

WithThrottle sets both producerThrottle and consumerThrottle If producerThrottle throttled, it input channel will be blocked(if using blocking mode). If consumerThrottle throttled, it output channel will be blocked.

func WithThrottleWindow

func WithThrottleWindow(window time.Duration) Option

WithThrottleWindow sets the interval time for throttle function checking.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the expiration time of each channel item. If the item not consumed in timeout duration, it will be aborted.

func WithTimeoutCallback

func WithTimeoutCallback(timeoutCallback func(interface{})) Option

WithTimeoutCallback sets callback function when item hit timeout.

type Throttle

type Throttle func(c Channel) bool

Throttle define channel Throttle function

Jump to

Keyboard shortcuts

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