ctavan/node-uuid — comment on commit d3162592053e3d7fead9f4e948810e2301550290
File: uuid.js line 88
By broofa:

A while loop for the express purpose of blocking execution is poor form. Particularly true in node.js-land which is aggressively non-blocking, even if it's for only a couple usecs. I think we can simplify things, and address the overflow problem, as follows ...

top of file, constant for epoch offset ...
```
// Offset in msecs from UUID epoch to UNIX epoch
var EPOCH_OFFSET = 12219292800000;
```

It'd be nice to have all our times in uuid epoch time, which is easier to do if we only `new Date()` in one place. So, above, just do ...
```
var last = 0;
```

Then, here, we can immediately init `now` to the uuid epoch time. And since the RFC doesn't really address the count overflow case, I think we're justified in using the clockseq as a fallback solution. ('Sure makes the code simpler!)
```
var now = new Date().getTime() + EPOCH_OFFSET;

count = now == last ? count + 1 : 0;
// Per 4.2.1.2, if time regresses we bump the clock sequence.
// (Or if we're generating more than 10M uuids/sec - an extremely unlikely case the RFC doesn't address)
if (now < last || count > UUIDS_PER_TICK) {
cs++;
count = 0;
}

last = now;
```

Oh... and I think the above lets us define UUIDS_PER_TICK = 10000, as god intended. ;)