flake-idgen
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -67,2 +67,9 @@ /** | ||
// Generates id in the same millisecond as the previous id | ||
if (time < this.lastTime) { | ||
if (cb) { | ||
setTimeout(self.next.bind(self, cb), this.lastTime - time); | ||
return; | ||
} | ||
throw new Error(`Clock moved backwards. Refusing to generate id for ${this.lastTime - time} milliseconds`); | ||
} | ||
if (time === this.lastTime) { | ||
@@ -69,0 +76,0 @@ |
{ | ||
"name": "flake-idgen", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Flake ID generator yields k-ordered, conflict-free ids in a distributed environment", | ||
@@ -5,0 +5,0 @@ "main": "flake-id-gen.js", |
@@ -101,2 +101,8 @@ Flake ID Generator | ||
### Counter overflow ### | ||
Flake ID Generator can generate up to 4096 unique identifiers within a millisecond. When generator tries to generate more than 4096 identifiers within a millisecond, the following things will happen: | ||
* When using `next()` without a callback function, an error is thrown. | ||
* When using `next(cb)` with a callback function, the callback function is called in the following millisecond without any error. | ||
### Additional generator setup parameters ### | ||
Flake Id generator constructor takes optional parameter (generator configuration options) with the following properties: | ||
@@ -186,4 +192,9 @@ * `datacenter` (5 bit) - datacenter identifier. It can have values from 0 to 31. | ||
### Formatting ### | ||
### Clock moving backward ### | ||
From time to time Node.js clock may move backward. In most cases it is only a few millisecond. However, as the generator relies on current timestamp, it won't be able to generate conflict-free identifiers (i.e. without duplicates) until the clock catches up with the last timestamp value. In case of clock move backward the following things will happen: | ||
* When using `next()` without a callback function, an error is thrown. | ||
* When using `next(cb)` with a callback function, the callback function is called with a new identifier generated once the clock catches up with the last timestamp. | ||
## Formatting ## | ||
Flake Id generator returns node Buffer representing 64-bit number for the sake of future extensions or returned buffer modifications. Node Buffer can also be very easily converted to string format. There is a NPM [biguint-format](https://npmjs.org/package/biguint-format) module which provides Buffer to string conversion functionality e.g. | ||
@@ -190,0 +201,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22116
231
250