hq-go-roundrobin is a Go (Golang) high-quality, concurrency-safe implementation of Round Robin(RR) algorithm for managing and cycling through a collection of items.
- Ensures safe concurrent access and modification of the round-robin queue.
- Prevents duplicate items in the queue, maintaining the integrity of the rotation.
- Customizable configuration to define how often the rotation should move to the next item.
- Provides a straightforward API for adding items and retrieving the next item in the round-robin sequence.
To install hq-go-roundrobin, run:
go get -v -u github.com/hueristiq/hq-go-roundrobinMake sure your Go environment is set up properly (Go 1.x or later is recommended).
Here's a simple example to get you started with hq-go-roundrobin:
package main
import (
"fmt"
hqgoroundrobin "github.com/hueristiq/hq-go-roundrobin"
)
func main() {
// Create a new round-robin instance with default options and initial items.
rr, err := hqgoroundrobin.New("item1", "item2", "item3")
if err != nil {
panic(err)
}
// Add more items if needed
rr.Add("item4", "item5")
// Retrieve and process items in a round-robin fashion
for i := 0; i < 10; i++ {
item := rr.Next()
fmt.Printf("Serving: %s\n", item.Value())
}
/*
Output:
item1
item2
item3
item4
item5
item1
item2
item3
item4
item5
*/
}Contributions are welcome and encouraged! Feel free to submit Pull Requests or report Issues. For more details, check out the contribution guidelines.
A big thank you to all the contributors for your ongoing support!
This package is licensed under the MIT license. You are free to use, modify, and distribute it, as long as you follow the terms of the license. You can find the full license text in the repository - Full MIT license text.