File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -117,13 +117,13 @@ Napi::FunctionReference Snowflake::constructor;
117
117
* Next 10 bits are filled with the node/machine id (max size can be 1024)
118
118
* Next 12 bits are filled with sequence which ensures that even if timestamp didn't change the value will be generated
119
119
*
120
- * Function can theorotically generate 1024 unique values within a millisecond without repeating values
120
+ * Function can theorotically generate 4096 unique values within a millisecond without repeating values
121
121
*/
122
122
Napi::Value Snowflake::getUniqueIDBigInt (const Napi::CallbackInfo &info)
123
123
{
124
124
Napi::Env env = info.Env ();
125
125
126
- uint64_t currentTimestamp = getCurrentTime ();
126
+ uint64_t currentTimestamp = getCurrentTime () - this -> _CUSTOM_EPOCH ;
127
127
128
128
if (currentTimestamp == this ->_lastTimestamp )
129
129
{
@@ -161,7 +161,10 @@ Napi::Value Snowflake::getUniqueID(const Napi::CallbackInfo &info)
161
161
{
162
162
this ->_sequence = (this ->_sequence + 1 ) & maxSequence;
163
163
if (this ->_sequence == 0 )
164
- std::this_thread::sleep_for (std::chrono::milliseconds (1000 ));
164
+ {
165
+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
166
+ currentTimestamp++;
167
+ }
165
168
}
166
169
else
167
170
{
You can’t perform that action at this time.
0 commit comments