2023-03-02 09:53:12 +00:00
|
|
|
// Package priorityq provides generic implementations of various concurrent,
|
|
|
|
// prioritized queues.
|
|
|
|
//
|
|
|
|
// # Behavior
|
|
|
|
//
|
|
|
|
// All types of queues in this module act similarly to buffered Go channels.
|
2023-03-02 03:22:37 +00:00
|
|
|
//
|
2023-03-02 09:53:12 +00:00
|
|
|
// - They are bounded to a fixed capacity, set at construction.
|
|
|
|
// - Closing and sending to an already-closed queue causes a panic.
|
|
|
|
// - Receivers can continue getting items after closure, and can use a final
|
|
|
|
// bool to determine when there are none remaining.
|
|
|
|
// - They are safe for multiple concurrent senders and receivers.
|
2023-03-02 03:22:37 +00:00
|
|
|
//
|
2023-03-02 09:53:12 +00:00
|
|
|
// # Implementation
|
2023-03-02 03:22:37 +00:00
|
|
|
//
|
2023-03-02 09:53:12 +00:00
|
|
|
// All data structures in this module use [generics], introduced in Go 1.18.
|
2023-03-02 03:22:37 +00:00
|
|
|
//
|
2023-03-02 09:53:12 +00:00
|
|
|
// All of the concurrent data structures in this package use a [sync.Mutex]
|
|
|
|
// and a few [sync.Cond] variables.
|
|
|
|
//
|
|
|
|
// [generics]: https://go.dev/blog/intro-generics
|
|
|
|
package priorityq
|
2023-03-03 05:35:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ErrEmpty means that an operation failed because the queue was empty.
|
|
|
|
var ErrEmpty error
|
|
|
|
|
|
|
|
// ErrFull means that an operation failed because the queue was full.
|
|
|
|
var ErrFull error
|
|
|
|
|
|
|
|
// ErrClosed means that an operation failed because the queue was closed.
|
|
|
|
var ErrClosed error
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
ErrEmpty = fmt.Errorf("queue is empty")
|
|
|
|
ErrFull = fmt.Errorf("queue is full")
|
|
|
|
ErrClosed = fmt.Errorf("queue is closed")
|
|
|
|
}
|