utils

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const PipelineBufSize = 4

Variables

This section is empty.

Functions

func IsChannelOpen

func IsChannelOpen[T any](ch chan T) bool

IsChannelOpen checks if the channel is open

func Must

func Must(err error)

func MustReturn

func MustReturn[T any](normal T, err error) T

func PanicIf

func PanicIf(cond bool, msg string)

func PanicIfErr

func PanicIfErr(err error)

Types

type Cleanup

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

func NewCleanup

func NewCleanup(cl func()) *Cleanup

func NewCleanupErr

func NewCleanupErr(cl func() error) *Cleanup

func (*Cleanup) Cleanup

func (c *Cleanup) Cleanup()

func (*Cleanup) Disarm

func (c *Cleanup) Disarm()

type Pipeline

type Pipeline[T any] struct {
	// contains filtered or unexported fields
}

Pipeline is an extension of Go channels that implements a channel with an infinite buffer. You need to call the `Start` method to start the channel, otherwise `Put` method will panic. It then behaves like a regular channel: `Put` method is used to submit messages, unlike regular channels it never blocks. `ReadChan` method can be used to get the read side of this pipeline. `Stop` method stops the pipeline. Unlike the regular channels, `Stop` method does not guarantee that all the pending messages are consumed.

func NewPipeline

func NewPipeline[T any]() *Pipeline[T]

NewPipeline creates a new pipeline

func (*Pipeline[T]) Len

func (p *Pipeline[T]) Len() int

Len returns the number of pending messages in the queue

func (*Pipeline[T]) Put

func (p *Pipeline[T]) Put(elem T)

Put enqueues the message into the pipeline. Unlike the regular channel write, it's a simple no-op if the pipeline has been stopped already

func (*Pipeline[T]) PutFront

func (p *Pipeline[T]) PutFront(elem T)

PutFront enqueues the message into the front of the pipeline

func (*Pipeline[T]) ReadChan

func (p *Pipeline[T]) ReadChan() <-chan T

ReadChan gets the read side of this pipeline

func (*Pipeline[T]) Start

func (p *Pipeline[T]) Start()

Start starts the pipeline. You need to call this method before you start enqueuing messages with `Put`

func (*Pipeline[T]) Stop

func (p *Pipeline[T]) Stop()

Stop stops the pipeline. It does NOT guarantee that all the queued messages are consumed before the pipeline is stopped.

Jump to

Keyboard shortcuts

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