Documentation ¶
Index ¶
- type Channel
- type Option
- func WithNonBlock() Option
- func WithRateThrottle(produceRate, consumeRate int) Option
- func WithSize(size int) Option
- func WithThrottle(producerThrottle, consumerThrottle Throttle) Option
- func WithThrottleWindow(window time.Duration) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTimeoutCallback(timeoutCallback func(interface{})) Option
- type Throttle
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
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 ¶
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 ¶
WithSize define the size of channel. If channel is full, it will block. It conflicts with WithNonBlock option.
func WithThrottle ¶
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 ¶
WithThrottleWindow sets the interval time for throttle function checking.
func WithTimeout ¶
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.