netmaker/serverctl/serverq.go
2022-01-18 09:06:43 -05:00

29 lines
633 B
Go

package serverctl
import (
"fmt"
"github.com/gravitl/netmaker/models"
)
// ServerQueue - holds data to be updated across the server
var ServerQueue chan models.ServerUpdateData
func init() {
ServerQueue = make(chan models.ServerUpdateData, 100)
}
// Push - Pushes ServerUpdateData to be used later
func Push(serverData models.ServerUpdateData) {
ServerQueue <- serverData
}
// Pop - fetches first available data from queue
func Pop() (models.ServerUpdateData, error) {
select {
case serverData := <-ServerQueue:
return serverData, nil
default:
return models.ServerUpdateData{}, fmt.Errorf("empty server queue")
}
}