Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monotonically increasing guarantee in the same millisecond #1

Closed
arjunyel opened this issue May 8, 2024 · 4 comments
Closed

Monotonically increasing guarantee in the same millisecond #1

arjunyel opened this issue May 8, 2024 · 4 comments

Comments

@arjunyel
Copy link

arjunyel commented May 8, 2024

What is the current behavior?

perry-mitchell/ulidx#14

If the current behavior is a bug, please provide the steps to reproduce

"given const [a, b, c] = [ulid(), ulid(), ulid()] c and b could sort lower than a" ulid/javascript#74

What is the expected behavior?

Monotonically increasing guarantee in the same millisecond

What is the motivation / use case for changing the behavior?

Help with sorting

Please tell us about your environment:

  • Version: Latest
  • Platform / OS version:
  • Node.js version: 20+
  • Rust version:
@yujiosaka
Copy link
Owner

@arjunyel
there is already a monotonic factory for it:
https://github.com/yujiosaka/wa-ulid?tab=readme-ov-file#monotonic-ulids

@arjunyel
Copy link
Author

@arjunyel there is already a monotonic factory for it: https://github.com/yujiosaka/wa-ulid?tab=readme-ov-file#monotonic-ulids

@yujiosaka yes but that factory doesn't provide guarantees in the same millisecond. If this library fixed that it would be a great reason to use it over the JavaScript library

@yujiosaka
Copy link
Owner

@arjunyel
you mean you want the non-monotonic factory to support the monotonic behavior?

@yujiosaka
Copy link
Owner

the monotonic factory increments the least significant bit for the same milliseconds, and is tested here:

wa-ulid/test/index.test.ts

Lines 201 to 207 in 383bf67

it("first call", () => {
assert.strictEqual("01ARYZ6S41YYYYYYYYYYYYYYYY", stubbedUlid(1469918176385));
});
it("second call with the same", () => {
assert.strictEqual("01ARYZ6S41YYYYYYYYYYYYYYYZ", stubbedUlid(1469918176385));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants