Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LIFO ¶
type LIFO struct {
// contains filtered or unexported fields
}
LIFO implements a last-in, first-out producer-consumer queue. Thread safe.
Example ¶
package main import ( "fmt" "github.com/grailbio/base/syncqueue" ) func main() { q := syncqueue.NewLIFO() q.Put("item0") q.Put("item1") q.Close() v0, ok := q.Get() fmt.Println("Item 0:", v0.(string), ok) v1, ok := q.Get() fmt.Println("Item 1:", v1.(string), ok) v2, ok := q.Get() fmt.Println("Item 2:", v2, ok) }
Output: Item 0: item1 true Item 1: item0 true Item 2: <nil> false
func (*LIFO) Close ¶
func (q *LIFO) Close()
Close informs the queue that no more objects will be added via Put().
type OrderedQueue ¶
type OrderedQueue struct {
// contains filtered or unexported fields
}
OrderedQueue is a queue that orders entries on their way out. An inserter enqueues each entry with an index, and when the receiver dequeues an entry, the entries arrive in the sequential order of their indices. An OrderedQueue has a maximum size; if the queue contains the next entry, the queue will accept up to maxSize entries. If the queue does not yet contain the next entry, the queue will block an insert that would make the size equal to maxSize unless the new entry is the next entry to be dequeued.
func NewOrderedQueue ¶
func NewOrderedQueue(maxSize int) *OrderedQueue
Create a new OrderedQueue with size maxSize.
func (*OrderedQueue) Close ¶
func (q *OrderedQueue) Close(err error) error
Close the ordered queue. In the normal case, err should be nil, and Close tells the OrderedQueue that all calls to Insert have completed. The user may not call Insert() after calling Close(). The user may close the OrderedQueue prematurely with a non-nil err while some calls to Insert() and/or Next() are blocking; in this case those calls that are blocking will return with err.
func (*OrderedQueue) Insert ¶
func (q *OrderedQueue) Insert(index int, value interface{}) error
Insert an entry into the queue with the specified sequence index. Insert blocks if the insert would make the queue full and the new entry is not the one next one in the output sequence. The sequence index should start at zero.
func (*OrderedQueue) Next ¶
func (q *OrderedQueue) Next() (value interface{}, ok bool, err error)
Next returns true and the next entry in sequence if the next entry is available. Next blocks if the next entry is not yet present. Next returns (nil, false) if there are no more entries, and the queue is closed.