channel

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: BSD-3-Clause Imports: 5 Imported by: 1

Documentation

Overview

Package channel defines the logger.

channel is using a global logger with some default parameters. It is disabled by default and the level can be increased using an environment variable:

CRY_LOG=trace
CRY_LOG=info

Index

Constants

View Source
const (
	ErrFailedToSend    = Error("Could not send data on channel.")
	ErrFailedToReceive = Error("Could not receive data from channel.")
)
View Source
const EnvLogLevel = "CRY_LOG"

EnvLogLevel is the name of the environment variable to change the logging level.

Variables

View Source
var Logger = zerolog.New(logout).Level(defaultLogLevel).
	With().Timestamp().Logger().
	With().Str("role", "cry chan").Logger()

Logger is a globally available logger instance. By default, it only prints error level messages but it can be changed through a environment variable.

Functions

This section is empty.

Types

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type Timed

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

func WithExpiration

func WithExpiration[T any](bufSize int) Timed[T]

WithExpiration creates a new channel of the given size and type

func (*Timed[T]) Channel

func (c *Timed[T]) Channel() chan T

Channel returns the raw channel used

func (*Timed[T]) Len

func (c *Timed[T]) Len() int

Len gives the current number of elements in the channel

func (*Timed[T]) NonBlockingReceive

func (c *Timed[T]) NonBlockingReceive() (e T, err error)

NonBlockingReceive removes an element from the channel or returns an error if it fails after the default timeout

func (*Timed[T]) NonBlockingReceiveWithContext

func (c *Timed[T]) NonBlockingReceiveWithContext(ctx context.Context) (T, error)

NonBlockingReceiveWithContext removes an element from the channel or returns an error if it fails in the given context.

func (*Timed[T]) NonBlockingReceiveWithTimeout

func (c *Timed[T]) NonBlockingReceiveWithTimeout(t time.Duration) (e T, err error)

NonBlockingReceiveWithTimeout removes an element from the channel or returns an error if it fails after the given timeout

func (*Timed[T]) NonBlockingSend

func (c *Timed[T]) NonBlockingSend(e T) error

NonBlockingSend adds an element in the channel, or returns an error if it fails after the default timeout.

func (*Timed[T]) NonBlockingSendWithContext

func (c *Timed[T]) NonBlockingSendWithContext(ctx context.Context, e T) error

NonBlockingSendWithContext adds an element in the channel, or returns an error if it fails in the given context.

func (*Timed[T]) NonBlockingSendWithTimeout

func (c *Timed[T]) NonBlockingSendWithTimeout(t time.Duration, e T) error

NonBlockingSendWithTimeout adds an element in the channel, or returns an error if it fails after the given timeout.

func (*Timed[T]) Receive

func (c *Timed[T]) Receive() T

Receive removes an element from the channel or logs a warning if it fails after the default timeout. Note: this is a blocking call as it waits on a channel.

func (*Timed[T]) ReceiveWithContext

func (c *Timed[T]) ReceiveWithContext(ctx context.Context) T

ReceiveWithContext removes an element from the channel or logs a warning if it fails in the given context. Note: this is a blocking call as it waits on a channel.

func (*Timed[T]) ReceiveWithTimeout

func (c *Timed[T]) ReceiveWithTimeout(t time.Duration) T

ReceiveWithTimeout removes an element from the channel or logs a warning if it fails after the given timeout. Note: this is a blocking call as it waits on a channel.

func (*Timed[T]) Send

func (c *Timed[T]) Send(e T)

Send adds an element in the channel, or logs a warning if it fails after default timeout. Note: this is a blocking call as it waits on a channel.

func (*Timed[T]) SendWithContext

func (c *Timed[T]) SendWithContext(ctx context.Context, e T)

SendWithContext adds an element in the channel, or logs a warning if it fails in the given context. Note: this is a blocking call as it waits on a channel.

func (*Timed[T]) SendWithTimeout

func (c *Timed[T]) SendWithTimeout(t time.Duration, e T)

SendWithTimeout adds an element in the channel, or logs a warning if it fails after the given timeout. Note: this is a blocking call as it waits on a channel.

Jump to

Keyboard shortcuts

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