File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ import type {
1111 Program as WasmProgram ,
1212} from '../pkg/fadroma_simf.d.ts' ;
1313
14+ /** WASM cache to download the binary only once. */
15+ let blob = null ;
1416/** Instance of SimplicityHL WASM module. */
1517export type Wasm = InitOutput ;
1618/** Load SimplicityHL WASM module. */
@@ -19,10 +21,16 @@ export async function Wasm ({
1921 // You can replace this with w.g. `readFile` from `fs/promises`; or polyfill `globalThis.fetch`
2022 fetch = globalThis . fetch
2123} = { } ) {
22- console . debug ( `Loading Fadroma SimplicityHL WASM module from ${ wasm } ` ) ;
2324 const conform = ( x : string | URL ) => new URL ( x ) . toString ( ) ;
2425 const wrap = await import ( '../pkg/fadroma_simf.js' ) ;
25- if ( ( typeof wasm === 'string' ) || ( wasm instanceof URL ) ) wasm = await fetch ( conform ( wasm ) ) ;
26+ if ( ! blob ) {
27+ if ( ( typeof wasm === 'string' ) || ( wasm instanceof URL ) ) {
28+ console . debug ( `Loading Fadroma SimplicityHL WASM module from ${ wasm } ` ) ;
29+ blob = await fetch ( conform ( wasm ) ) ;
30+ } else {
31+ throw new Error ( `Invalid WASM URL, need string or URL, got: ${ wasm } ` )
32+ }
33+ }
2634 await wrap . default ( wasm ) ;
2735 return wrap ;
2836}
You can’t perform that action at this time.
0 commit comments