Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Don't throw 10k error so early, add another test #28

Merged
merged 2 commits into from

2 participants

@ctavan

Hey Robert,

thanks for your good patch, it does exactly what I was expecting. I've just one improvement which is moving the check for nsecs >= 10000 down a bit so we don't throw errors when they are not entirely necessary.

I'd love to see this merged to the master!

Thanks,
Christoph

@broofa broofa merged commit 2343e92 into broofa:explicit_time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 7 deletions.
  1. +9 −1 test/test.js
  2. +6 −6 uuid.js
View
10 test/test.js
@@ -79,11 +79,19 @@ try {
assert(thrown, 'Exception thrown when > 10K ids created in 1 ms');
// Verify clock regression bumps clockseq
+var uidt = uuid.v1({msecs: TIME});
+var uidtb = uuid.v1({msecs: TIME - 1});
+assert(
+ parseInt(uidtb.split('-')[3], 16) - parseInt(uidt.split('-')[3], 16) === 1,
+ 'Clock regression by msec increments the clockseq'
+);
+
+// Verify clock regression bumps clockseq
var uidtn = uuid.v1({msecs: TIME, nsecs: 10});
var uidtnb = uuid.v1({msecs: TIME, nsecs: 9});
assert(
parseInt(uidtnb.split('-')[3], 16) - parseInt(uidtn.split('-')[3], 16) === 1,
- 'Clock regression increments the clockseq'
+ 'Clock regression by nsec increments the clockseq'
);
// Verify explicit options produce expected id
View
12 uuid.js
@@ -139,12 +139,6 @@
// cycle to simulate higher resolution clock
var nsecs = options.nsecs != null ? options.nsecs : _lastNSecs + 1;
- // Per 4.2.1.2 If generator creates more than one uuid per 100-ns
- // interval, throw an error
- if (nsecs >= 10000) {
- throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
- }
-
// Time since last uuid creation (in msecs)
var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
@@ -160,6 +154,12 @@
nsecs = 0;
}
+ // Per 4.2.1.2 If generator creates more than one uuid per 100-ns
+ // interval, throw an error
+ if (nsecs >= 10000) {
+ throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
+ }
+
_lastMSecs = msecs;
_lastNSecs = nsecs;
_clockseq = clockseq;
Something went wrong with that request. Please try again.