doc: add and improve comments
This commit is contained in:
parent
d83acc77b2
commit
d0b1260f62
12 changed files with 50 additions and 26 deletions
|
@ -11,6 +11,8 @@ import (
|
|||
var mu sync.Mutex // to synchronize access to shared state
|
||||
var timer Timer
|
||||
|
||||
// Update `State` with the remaining seconds of the passed timer
|
||||
// until the timer sends an End or Abort signal
|
||||
func waitForTimer(t Timer) bool {
|
||||
for {
|
||||
select {
|
||||
|
@ -24,7 +26,7 @@ func waitForTimer(t Timer) bool {
|
|||
}
|
||||
}
|
||||
|
||||
// RunPomodoro iterates the Pomodoro work/break sessions.
|
||||
// RunPomodoro iterates the Pomodoro work/break sessions
|
||||
func RunPomodoro() {
|
||||
mu.Lock()
|
||||
shared.State.Ongoing = true
|
||||
|
@ -38,12 +40,14 @@ func RunPomodoro() {
|
|||
|
||||
shared.State.Session = session
|
||||
|
||||
// Work
|
||||
shared.State.Mode = "Work"
|
||||
go timer.Start(pomodoroConfig.Work)
|
||||
if !waitForTimer(timer) {
|
||||
break
|
||||
}
|
||||
|
||||
// Breaks
|
||||
if session < pomodoroConfig.Sessions {
|
||||
shared.State.Mode = "ShortBreak"
|
||||
go timer.Start(pomodoroConfig.ShortBreak)
|
||||
|
@ -56,6 +60,8 @@ func RunPomodoro() {
|
|||
if !waitForTimer(timer) {
|
||||
break
|
||||
}
|
||||
|
||||
// send "End" state for one second
|
||||
shared.State.Mode = "End"
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
@ -92,13 +98,13 @@ func ResumePomodoro() {
|
|||
|
||||
func IsPomodoroOngoing() bool {
|
||||
mu.Lock()
|
||||
defer mu.Unlock() // Ensures that the mutex is unlocked after the function is done
|
||||
defer mu.Unlock()
|
||||
return shared.State.Ongoing
|
||||
}
|
||||
|
||||
func IsPomodoroPaused() bool {
|
||||
mu.Lock()
|
||||
defer mu.Unlock() // Ensures that the mutex is unlocked after the function is done
|
||||
defer mu.Unlock()
|
||||
return shared.State.Paused
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue