go实现,获取下一时间戳前,暂停1ms
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* 版权属于:yitter(yitter@126.com)
|
||||
* 开源地址:https://github.com/yitter/idgenerator
|
||||
*/
|
||||
|
||||
package regworkerid
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user