Documentation ¶
Index ¶
- Variables
- type Queue
- func (q *Queue) Get(timeout time.Duration) (interface{}, error)
- func (q *Queue) GetNoWait() (interface{}, error)
- func (q *Queue) IsEmpty() bool
- func (q *Queue) IsFull() bool
- func (q *Queue) Put(val interface{}, timeout time.Duration) error
- func (q *Queue) PutNoWait(val interface{}) error
- func (q *Queue) Size() int
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyQueue is returned when queue is empty. ErrEmptyQueue = errors.New("queue is empty") // ErrFullQueue is returned when queue is full. ErrFullQueue = errors.New("queue is full") )
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is data structure, which has much similar behavior with channel.
func New ¶
New create a new Queue, The maxSize variable sets the max Queue size. If maxSize is zero, Queue will be infinite size, and Put always no wait.
func (*Queue) Get ¶
Get gets an element from Queue. If timeout less than 0, If Queue is empty, return (nil, ErrEmptyQueue); If timeout equals to 0, block until get a value from Queue; If timeout greater than 0, wait timeout seconds until get a value from Queue, if timeout passed, return (nil, ErrEmptyQueue).
func (*Queue) Put ¶
Put puts an element into Queue. If timeout less than 0, If Queue is full, return (nil, ErrFullQueue); If timeout equals to 0, block until put a value into Queue; If timeout greater than 0, wait timeout seconds until put a value into Queue, if timeout passed, return (nil, ErrFullQueue).