Skip to content

Commit

Permalink
fix(lyra): removes access to process and performance global variable …
Browse files Browse the repository at this point in the history
…if not supported in the runtime

fix #98
  • Loading branch information
micheleriva committed Aug 21, 2022
1 parent 00f68f7 commit b51456c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/lyra/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ export function formatNanoseconds(value: number | bigint): string {
}

export function getNanosecondsTime(): bigint {
if (isServer) {
if (typeof process !== "undefined") {
return process.hrtime.bigint();
}

return BigInt(Math.floor(performance.now() * 1e6));
if (typeof performance !== "undefined") {
return BigInt(Math.floor(performance.now() * 1e6));
}

// @todo: fallback to V8 native method to get microtime
return BigInt(0);
}

export function uniqueId(): string {
Expand Down

0 comments on commit b51456c

Please sign in to comment.