Skip to content

Commit

Permalink
use snowyflake
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric committed May 27, 2023
1 parent e277c04 commit 54880d2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 50 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"dependencies": {
"@huggingface/inference": "^2.5.0",
"p-queue": "^6.6.2",
"snowyflake": "^2.0.0",
"throat": "^6.0.2",
"tslib": "^2.5.0",
"ws": "^8.13.0"
Expand Down
11 changes: 7 additions & 4 deletions src/utls/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Snowflake } from "./snowflake";

export * from "./snowflake";
import { Snowyflake, Epoch } from "snowyflake";

export const sleep = async (ms: number): Promise<void> =>
await new Promise((resolve) => setTimeout(resolve, ms));

export const random = (min: number, max: number): number =>
Math.floor(Math.random() * (max - min) + min);

const snowflake = new Snowflake(0);
// const snowflake = new Snowflake(1);
const snowflake = new Snowyflake({
workerId: 1n,
epoch: Epoch.Twitter, // BigInt timestamp
});

export const nextNonce = (): string => snowflake.nextId().toString();
46 changes: 0 additions & 46 deletions src/utls/snowflake.ts

This file was deleted.

5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ prettier@^2.8.8:
resolved "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==

snowyflake@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/snowyflake/-/snowyflake-2.0.0.tgz#9514fb3540b290b71fec8efb6a737d32c4dc8105"
integrity sha512-BxeqV0KJxJASu6EBJGUkX194Zhh37AEa0ow/JRK39icWbLTG9Wl/7LAL6a/ZMSjNm4O9pZk6QoLcWP7f/YKmtA==

source-map-support@^0.5.21:
version "0.5.21"
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz"
Expand Down

0 comments on commit 54880d2

Please sign in to comment.