mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
fix(open-sse): serialize xxhash startup in cch hashing
Cache the in-flight xxhash-wasm initialization so concurrent calls reuse the same promise before the raw hash function is available. This avoids redundant loader work and prevents races during early CCH computations.
This commit is contained in:
@@ -17,12 +17,18 @@ import xxhashInit from "xxhash-wasm";
|
||||
const CCH_SEED = 0x6e52736ac806831en;
|
||||
const CCH_PATTERN = /\bcch=([0-9a-f]{5});/;
|
||||
|
||||
let xxhashPromise: Promise<void> | null = null;
|
||||
let xxhash64Fn: ((input: Uint8Array, seed: bigint) => bigint) | null = null;
|
||||
|
||||
async function ensureXxhash() {
|
||||
if (xxhash64Fn) return;
|
||||
const hasher = await xxhashInit();
|
||||
xxhash64Fn = hasher.h64Raw;
|
||||
if (!xxhashPromise) {
|
||||
xxhashPromise = (async () => {
|
||||
const hasher = await xxhashInit();
|
||||
xxhash64Fn = hasher.h64Raw;
|
||||
})();
|
||||
}
|
||||
return xxhashPromise;
|
||||
}
|
||||
|
||||
export async function computeCCH(bodyBytes: Uint8Array): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user