1
0
mirror of synced 2025-12-10 15:18:16 +08:00

go实现,获取下一时间戳前,暂停1ms

This commit is contained in:
yitter
2022-07-09 20:21:55 +08:00
parent 848cd3bb6f
commit c916112dd7
3 changed files with 21 additions and 8 deletions

View File

@@ -232,6 +232,7 @@ func (m1 *SnowWorkerM1) GetCurrentTimeTick() int64 {
func (m1 *SnowWorkerM1) GetNextTimeTick() int64 {
tempTimeTicker := m1.GetCurrentTimeTick()
for tempTimeTicker <= m1._LastTimeTick {
time.Sleep(time.Duration(1) * time.Millisecond)
tempTimeTicker = m1.GetCurrentTimeTick()
}
return tempTimeTicker

View File

@@ -1,3 +1,10 @@
/*
* <20><>Ȩ<EFBFBD><C8A8><EFBFBD>ڣ<EFBFBD>yitter(yitter@126.com)
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0BCAD>guoyahao
* <20><><EFBFBD><EFBFBD><EFBFBD>޶<EFBFBD><DEB6><EFBFBD>yitter
* <20><>Դ<EFBFBD><D4B4>ַ<EFBFBD><D6B7>https://github.com/yitter/idgenerator
*/
package idgen
import (
@@ -17,14 +24,14 @@ func SetIdGenerator(options *IdGeneratorOptions) {
// NextId .
func NextId() int64 {
if idGenerator == nil {
singletonMutex.Lock()
defer singletonMutex.Unlock()
if idGenerator == nil {
options := NewIdGeneratorOptions(1)
idGenerator = NewDefaultIdGenerator(options)
}
}
//if idGenerator == nil {
// singletonMutex.Lock()
// defer singletonMutex.Unlock()
// if idGenerator == nil {
// options := NewIdGeneratorOptions(1)
// idGenerator = NewDefaultIdGenerator(options)
// }
//}
return idGenerator.NewLong()
}

View File

@@ -1,3 +1,8 @@
/*
* 版权属于yitter(yitter@126.com)
* 开源地址https://github.com/yitter/idgenerator
*/
package regworkerid
import (