|
|
|
@ -38,12 +38,23 @@ func main() {
|
|
|
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a fan-out mechanism for events
|
|
|
|
|
|
|
|
eventBroadcaster := make(chan derby.Event, 10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start the event broadcaster
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
for event := range clock.Events() {
|
|
|
|
|
|
|
|
eventBroadcaster <- event
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
close(eventBroadcaster)
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
// Start web interface if enabled
|
|
|
|
// Start web interface if enabled
|
|
|
|
if !*noWeb {
|
|
|
|
if !*noWeb {
|
|
|
|
wg.Add(1)
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
defer wg.Done()
|
|
|
|
startWebInterface(clock, *webPort, sigChan)
|
|
|
|
startWebInterface(clock, eventBroadcaster, *webPort, sigChan)
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -52,7 +63,7 @@ func main() {
|
|
|
|
wg.Add(1)
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
defer wg.Done()
|
|
|
|
startTerminalInterface(clock, sigChan)
|
|
|
|
startTerminalInterface(clock, eventBroadcaster, sigChan)
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -66,9 +77,9 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// startWebInterface initializes and runs the web interface
|
|
|
|
// startWebInterface initializes and runs the web interface
|
|
|
|
func startWebInterface(clock *derby.DerbyClock, webPort int, sigChan chan os.Signal) {
|
|
|
|
func startWebInterface(clock *derby.DerbyClock, events <-chan derby.Event, webPort int, sigChan chan os.Signal) {
|
|
|
|
// Create and start the web server
|
|
|
|
// Create and start the web server
|
|
|
|
server, err := web.NewServer(clock, webPort)
|
|
|
|
server, err := web.NewServer(clock, events, webPort)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error creating web server: %v\n", err)
|
|
|
|
fmt.Printf("Error creating web server: %v\n", err)
|
|
|
|
sigChan <- syscall.SIGTERM
|
|
|
|
sigChan <- syscall.SIGTERM
|
|
|
|
@ -85,7 +96,7 @@ func startWebInterface(clock *derby.DerbyClock, webPort int, sigChan chan os.Sig
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// startTerminalInterface initializes and runs the terminal interface
|
|
|
|
// startTerminalInterface initializes and runs the terminal interface
|
|
|
|
func startTerminalInterface(clock *derby.DerbyClock, sigChan chan os.Signal) {
|
|
|
|
func startTerminalInterface(clock *derby.DerbyClock, events <-chan derby.Event, sigChan chan os.Signal) {
|
|
|
|
fmt.Println("Terminal interface started")
|
|
|
|
fmt.Println("Terminal interface started")
|
|
|
|
|
|
|
|
|
|
|
|
// Reset the clock to start fresh
|
|
|
|
// Reset the clock to start fresh
|
|
|
|
@ -106,7 +117,7 @@ func startTerminalInterface(clock *derby.DerbyClock, sigChan chan os.Signal) {
|
|
|
|
// Process events from the clock
|
|
|
|
// Process events from the clock
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
raceResults := make([]*derby.Result, 0)
|
|
|
|
raceResults := make([]*derby.Result, 0)
|
|
|
|
for event := range clock.Events() {
|
|
|
|
for event := range events {
|
|
|
|
switch event.Type {
|
|
|
|
switch event.Type {
|
|
|
|
case derby.EventRaceStart:
|
|
|
|
case derby.EventRaceStart:
|
|
|
|
fmt.Println("\n🏁 Race started!")
|
|
|
|
fmt.Println("\n🏁 Race started!")
|
|
|
|
|