Skip to content

Commit d2f8caa

Browse files
committed
refactor: simplify WASM init
1 parent fb36d31 commit d2f8caa

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

cmd/chromad/static/chroma.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,11 @@ class ChromaWASM {
1414
async init() {
1515
try {
1616
// Create a new Go instance
17-
this.go = new Go();
18-
19-
// Load the WASM module
20-
const wasmResponse = await fetch("./static/chroma.wasm");
21-
if (!wasmResponse.ok) {
22-
throw new Error(`Failed to fetch chroma.wasm: ${wasmResponse.status}`);
23-
}
24-
25-
const wasmBytes = await wasmResponse.arrayBuffer();
26-
const wasmModule = await WebAssembly.instantiate(
27-
wasmBytes,
28-
this.go.importObject,
29-
);
30-
31-
this.wasm = wasmModule.instance;
32-
33-
// Run the Go program
34-
this.go.run(this.wasm);
35-
36-
this.ready = true;
17+
const go = new Go();
18+
WebAssembly.instantiateStreaming(fetch("./static/chroma.wasm"), go.importObject).then((result) => {
19+
go.run(result.instance);
20+
this.ready = true;
21+
});
3722
console.log("Chroma WASM module initialized successfully");
3823
} catch (error) {
3924
console.error("Failed to initialize Chroma WASM module:", error);

0 commit comments

Comments
 (0)