fix: use atomic for ids (#634)

closes #622

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Co-authored-by: Ville Valkonen <weezel@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2024-10-07 15:26:12 -03:00
committed by GitHub
co-authored by Ville Valkonen
parent 4382fdf1c6
commit 9a262e9b0f
5 changed files with 15 additions and 48 deletions
+3 -9
View File
@@ -2,22 +2,16 @@
package timer
import (
"sync"
"sync/atomic"
"time"
tea "github.com/charmbracelet/bubbletea"
)
var (
lastID int
idMtx sync.Mutex
)
var lastID int64
func nextID() int {
idMtx.Lock()
defer idMtx.Unlock()
lastID++
return lastID
return int(atomic.AddInt64(&lastID, 1))
}
// Authors note with regard to start and stop commands: