Skip to content

Commit

Permalink
feat: adds an interface to the struct
Browse files Browse the repository at this point in the history
  • Loading branch information
ikouchiha47 committed Mar 4, 2024
1 parent 34b2ac9 commit 7753473
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const (
customEpoch = 1420070400000
)

type SnowflakeGenerator interface {
NextID() int64
}

type SequenceGenerator struct {
mu sync.Mutex
lastTimeStamp int64
Expand Down Expand Up @@ -57,7 +61,7 @@ func (s *SequenceGenerator) NextID() int64 {
s.mu.Lock()
defer s.mu.Unlock()

var currentTimestamp = timestamp()
currentTimestamp := timestamp()

if currentTimestamp < s.lastTimeStamp {
panic("system clock is destroyed")
Expand Down

0 comments on commit 7753473

Please sign in to comment.