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

fix: check for hrtime func availability #102

Merged
merged 1 commit into from
Aug 24, 2022

Conversation

castarco
Copy link
Contributor

Fixes #101

Copy link
Member

@micheleriva micheleriva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@micheleriva
Copy link
Member

Thank you @castarco !

@micheleriva micheleriva merged commit 99eb188 into oramasearch:main Aug 24, 2022
@@ -35,7 +35,7 @@ export function formatNanoseconds(value: number | bigint): string {
}

export function getNanosecondsTime(): bigint {
if (typeof process !== "undefined") {
if (typeof process !== "undefined" && process.hrtime !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feels a little inconsistent here... do we need an issue to use !== undefined everywhere? Using typeof x !== "string" feels kind of old school, right???

Copy link
Contributor Author

@castarco castarco Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first part of the conditional makes sense because, if process is not declared (as opposed to be undefined), then comparing it against undefined, or trying to do something like if (process), will raise an error (I actually tried it this morning).

It is true, though, that the second part of the conditional could have been simplified.

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

Successfully merging this pull request may close these issues.

Process.hrtime is undefined with Next.js since 0.0.5
3 participants