feat(server): restructure Pomodoro server into modular components
- move server logic to cmd/server/main.go
- create packages for websocket, pomodoro and broadcast handling
- define models for messages
- remove old GoTomato.go file
- update README
🤖
This commit is contained in:
parent
6d73711341
commit
c59f737eb7
10 changed files with 224 additions and 157 deletions
39
internal/pomodoro/pomodoro.go
Normal file
39
internal/pomodoro/pomodoro.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package pomodoro
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
workDuration = 15 * 60
|
||||
shortBreakDuration = 5 * 60
|
||||
longBreakDuration = 10 * 60
|
||||
sessions = 4
|
||||
)
|
||||
|
||||
var mu sync.Mutex // to synchronize access to shared state
|
||||
|
||||
// RunPomodoroTimer iterates the Pomodoro work/break sessions.
|
||||
func RunPomodoroTimer(clients map[*websocket.Conn]bool) {
|
||||
mu.Lock()
|
||||
timerRunning = true
|
||||
|
||||
for session := 1; session <= sessions; session++ {
|
||||
if !startTimer(clients, workDuration, "Work", session) {
|
||||
break
|
||||
}
|
||||
if session == sessions {
|
||||
if !startTimer(clients, longBreakDuration, "LongBreak", session) {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if !startTimer(clients, shortBreakDuration, "ShortBreak", session) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
timerRunning = false
|
||||
mu.Unlock()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue