Categorygithub.com/rvagg/go-prioritywaitqueue
repositorypackage
1.1.0
Repository: https://github.com/rvagg/go-prioritywaitqueue.git
Documentation: pkg.go.dev

# 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