Skip to content

Instantly share code, notes, and snippets.

@jed
Last active December 20, 2015 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jed/6046015 to your computer and use it in GitHub Desktop.
Save jed/6046015 to your computer and use it in GitHub Desktop.
returns unique timestamps, delays subsequent calls if called more than once per millisecond.
var then = Date.now()
function monotonicTimestamp(cb) {
var now = Date.now()
now > then
? setImmediate(cb, null, then = now)
: setTimeout(cb, then - now, null, ++then)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment