Skip to content

Commit

Permalink
fix Fast for concurrence (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bingoohuang authored Jul 15, 2024
1 parent 8d675e5 commit b76d42d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tsid.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func NewTsid(number int64) *tsid {
// Fast returns a pointer to new random tsid
func Fast() *tsid {
// Incrementing before using it
atomicCounter.Add(1)
cnt := atomicCounter.Add(1)

time := (time.Now().UnixMilli() - TSID_EPOCH) << RANDOM_BITS
tail := atomicCounter.Load() & uint32(RANDOM_MASK)
tail := cnt & uint32(RANDOM_MASK)

return NewTsid(time | int64(tail))
}
Expand Down

0 comments on commit b76d42d

Please sign in to comment.