Closed teyou closed 1 year ago
Hi, thanks for reporting the issue. This is not quite the way the library is supposed to be consumed. new Snowflake
returns a stateful object which ensures to never return duplicate values but if these objects are being generated in each iteration then the invariant won't hold true.
Can you try the followiing:
const uuids = new Map();
+ const cid = new Snowflake({ custom_epoch: 1262304000000 });
for (let index = 0; index < 100000; index++) {
- const cid = new Snowflake({ custom_epoch: 1262304000000 });
const uuid = cid.getUniqueID();
if (uuids.has(uuid)) {
const prevIndex = uuids.get(uuid)
console.error(`duplicate uuid: ${uuid.toString()} with index: ${prevIndex}`)
break;
}
uuids.set(uuid, index);
console.log(`${index} --> ${uuid.toString()}`)
}
There is a similar test that I run in the CI, you can check out that as well: https://github.com/utkarsh-pro/nodejs-snowflake/blob/666d94b8ca6f5fe1820c08bce42d1768c6fcc5d3/tests/snowflake_core.rs#L144
@utkarsh-pro ah, got it!
Thanks for the prompt reply!
To replicate:
Sample output
@utkarsh-pro any idea where's wrong?