func timeNowUniqueUnix() (ms int64, uniqueNum int64) {
	now := time.Now()
	newNano := now.UnixNano()
	for {
		prevLastNano := lastNano
		if prevLastNano < newNano && atomic.CompareAndSwapInt64(&lastNano, prevLastNano, newNano) {
			ms = newNano / int64(time.Millisecond)
			// If was same ms as seen before, set uniqueNum to the nano part
			if prevLastNano/int64(time.Millisecond) == ms {
				uniqueNum = newNano%int64(time.Millisecond) + 1
			}
			return
		}
		newNano = prevLastNano + 1
	}
}
// uniqueNano is 0 if ms is first time seen, otherwise a unique num in combination with ms
uniqueNano is 0 if ms is first time seen, otherwise a unique num in combination with ms
// uniqueNano is 0 if ms is first time seen otherwise a unique num in combination with ms
func timeNowUniqueUnix() (ms int64, uniqueNum int64) {
	now := time.Now()
	newNano := now.UnixNano()
	for {
		prevLastNano := lastNano
		if prevLastNano < newNano && atomic.CompareAndSwapInt64(&lastNano, prevLastNano, newNano) {
			ms = newNano / int64(time.Millisecond)
			if prevLastNano/int64(time.Millisecond) == ms {
				uniqueNum = newNano%int64(time.Millisecond) + 1
			}
			return
		}
		newNano = prevLastNano + 1
	}
}
func timeNowUniqueUnix ( ) ( ms int64 , uniqueNum int64 ) { now := time . Now ( ) newNano := now . UnixNano ( ) for { prevLastNano := lastNano if prevLastNano < newNano && atomic . CompareAndSwapInt64 ( & lastNano , prevLastNano , newNano ) { ms = newNano / int64 ( time . Millisecond ) if prevLastNano / int64 ( time . Millisecond ) == ms { uniqueNum = newNano % int64 ( time . Millisecond ) + 1 } return } newNano = prevLastNano + 1 } }
uniqueNano is 0 if ms is first time seen, otherwise a unique num in combination with ms
uniqueNano is 0 if ms is first time seen otherwise a unique num in combination with ms
// If was same ms as seen before, set uniqueNum to the nano part