working commit
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package auxid
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
var (
|
||||
idMtx sync.Mutex
|
||||
lastID int64
|
||||
)
|
||||
|
||||
func GenID() int64 {
|
||||
// 53 bit limit for js
|
||||
// See https://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript
|
||||
idMtx.Lock()
|
||||
defer idMtx.Unlock()
|
||||
for {
|
||||
id := (time.Now().UnixNano() / 1000) // - 10000000000000
|
||||
if id != lastID {
|
||||
lastID = id
|
||||
return id
|
||||
}
|
||||
time.Sleep(1 * time.Microsecond)
|
||||
}
|
||||
//10467328383814
|
||||
}
|
||||
Reference in New Issue
Block a user