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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

return process.hrtime.bigint();
}

Expand Down