netmaker/serverctl/serverq.go

30 lines
633 B
Go
Raw Normal View History

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