Skip to content

Commit

Permalink
Merge pull request #1 from foxglove/achim/performance-random-id-gener…
Browse files Browse the repository at this point in the history
…ation

make random id generation more performant
  • Loading branch information
defunctzombie authored Jan 24, 2024
2 parents 216a78c + 774f240 commit 3aead4f
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/comlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ function requestResponseMessage(
transfers?: Transferable[]
): Promise<WireValue> {
return new Promise((resolve) => {
const id = generateUUID();
const id = Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER).toString();
ep.addEventListener("message", function l(ev: MessageEvent) {
if (!ev.data || !ev.data.id || ev.data.id !== id) {
return;
Expand All @@ -614,9 +614,3 @@ function requestResponseMessage(
});
}

function generateUUID(): string {
return new Array(4)
.fill(0)
.map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))
.join("-");
}

0 comments on commit 3aead4f

Please sign in to comment.