types

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Amount of time to delay semaphore acquisition loops.
	MailboxDelaySleep  time.Duration = 50 * time.Millisecond
	DefaultCtxDeadline time.Duration = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Module  string
	Message string
}

Custom error structure.

This is compatible with the `error` interface and provides `Unwrap` support.

func NewError

func NewError(module string, format string, args ...interface{}) *Error

Create a new error object.

func NewErrorAndLog

func NewErrorAndLog(module string, format string, args ...interface{}) *Error

Create a new error object and immediately log it.

func (*Error) Error

func (e *Error) Error() string

Return a human-readable string representation of the error.

func (*Error) Log

func (e *Error) Log()

Log the error.

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

Convert the error to a JSON string.

func (*Error) String

func (e *Error) String() string

Return a human-readable string representation of the error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap the error.

type Mailbox

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

Mailbox structure.

This is a cheap implementation of a mailbox.

It uses two semaphores to control read and write access, and contains a single datum.

This is *not* a queue!

func NewMailbox

func NewMailbox() *Mailbox

Create and return a new empty mailbox.

Note: this acquires the `preventRead` semaphore.

func (*Mailbox) Full

func (m *Mailbox) Full() bool

Does the mailbox contain a value?

func (*Mailbox) Get

func (m *Mailbox) Get() (interface{}, bool)

Get an element from the mailbox. Defaults to using a context with a deadline of 5 seconds.

func (*Mailbox) GetWithContext

func (m *Mailbox) GetWithContext(ctx context.Context) (interface{}, bool)

func (*Mailbox) Put

func (m *Mailbox) Put(elem interface{})

Put an element into the mailbox.

type Pair

type Pair struct {
	First  interface{}
	Second interface{}
}

Pair structure.

This is a cheap implementation of a pair (aka two-value tuple).

I wish generics were a thing.

func NewEmptyPair

func NewEmptyPair() *Pair

Create a new empty pair.

func NewPair

func NewPair(first interface{}, second interface{}) *Pair

Create a new pair.

func (*Pair) String

func (p *Pair) String() string

Return a string representation of the pair.

type Queue

type Queue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Queue structure.

This is a cheap implementation of a LIFO queue.

func NewBoundedQueue

func NewBoundedQueue(bounds int) *Queue

func NewQueue

func NewQueue() *Queue

Create a new empty queue.

func (*Queue) Full

func (q *Queue) Full() bool

Is the queue full?

func (*Queue) Get

func (q *Queue) Get() (interface{}, bool)

Remove an element from the end of the queue and return it.

func (*Queue) Len

func (q *Queue) Len() int

Return the number of elements in the queue.

func (*Queue) Put

func (q *Queue) Put(elem interface{}) bool

Append an element to the queue. Returns `false` if there is no more room in the queue.

Jump to

Keyboard shortcuts

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