tokenqueue

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrorClosed is returned when the queue has been closed
	ErrorClosed = errors.New("Queue has been closed")
)

Functions

This section is empty.

Types

type Queue

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

Queue is a type of queue that allows requesting token (for example command slots) and passing them to a processor that can return them after the command has been completed

func NewQueue

func NewQueue(maximumCapacity int, initialCapacity int, factory TokenFactory) *Queue

NewQueue creates the tokenqueue with a given maximum capacity, initial capacity and factory

func (*Queue) Close

func (q *Queue) Close()

Close closes the tokenqueue

func (*Queue) CommitToken

func (q *Queue) CommitToken(t Token) error

CommitToken takes a token returned by GetAvailableToken and commits it after preparing

func (*Queue) EnableDisableTokens

func (q *Queue) EnableDisableTokens(amount int) bool

EnableDisableTokens is used to temporary change the amount of tokens that are available Returns true if the update is possible, false if not. Eg. the BLE HCI command queue is dynamic

func (*Queue) GetAvailableToken

func (q *Queue) GetAvailableToken(ctx context.Context) (Token, error)

GetAvailableToken will return a token for a free slot to the client

func (*Queue) GetAvailableTokenChan

func (q *Queue) GetAvailableTokenChan(ctx context.Context) <-chan (Token)

GetAvailableTokenChan returns a channel from which available tokens can be read

func (*Queue) GetCommittedToken

func (q *Queue) GetCommittedToken(ctx context.Context) (Token, error)

GetCommittedToken will return a committed token to the processor

func (*Queue) GetCommittedTokenChan

func (q *Queue) GetCommittedTokenChan(ctx context.Context) <-chan (Token)

GetCommittedTokenChan returns a channel from which committed tokens can be read

func (*Queue) ReleaseToken

func (q *Queue) ReleaseToken(t Token) error

ReleaseToken takes a token returned by GetCommittedToken and releases it after processing

type Token

type Token interface {
	Cleanup()
}

Token is an interface that a token should implement. The cleanup method is called upon closing the queue

type TokenFactory

type TokenFactory func() Token

TokenFactory is a function that is called when creating a queue. It should return pointers to tokens

Jump to

Keyboard shortcuts

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