mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-05 04:36:07 +00:00
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:
co-authored by
Ville Valkonen
parent
4382fdf1c6
commit
9a262e9b0f
+3
-9
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user