# README
go-prioritywaitqueue
go-prioritywaitqueue implements a blocking queue for prioritised coordination of goroutine execution.
Install
go get github.com/rvagg/go-prioritywaitqueue
Usage
// global setup
var workerCmp prioritywaitqueue.ComparePriority[*worker] = func(a *worker, b *worker) bool {
return a.id < b.id
}
queue := prioritywaitqueue.New(workerCmp)
// per-goroutine use
func (w *worker) doSomething() {
done := w.queue.Wait(w) // will block until this goroutine is allowed to run
defer done() // signal that the work has completed and another goroutine can run
// ... work
}
License
Copyright © 2022 Rod Vagg
Licensed under either of
- Apache 2.0, (LICENSE-APACHE / http://www.apache.org/licenses/LICENSE-2.0)
- MIT (LICENSE-MIT / http://opensource.org/licenses/MIT)
# Functions
New creates a new PriorityWaitQueue with the provided ComparePriority function for type T.
WithClock sets the clock to use for the PriorityWaitQueue.
WithInitialPause sets an initial pause for the first call to Wait() on the PriorityWaitQueue.
# Interfaces
PriorityWaitQueue is a blocking queue for coordinating goroutines, providing a gating mechanism such that only one goroutine may run at a time, where the goroutine allowed to run is chosen based on a priority comparison function.
# Type aliases
ComparePriority should return true if a has a higher priority, and therefore should run, BEFORE b.
No description provided by the author