@@ -34,7 +34,7 @@ export abstract class DuckDBBrowserBindings extends DuckDBBindingsBase {
34
34
}
35
35
36
36
/** Instantiate the wasm module */
37
- protected instantiateWasm (
37
+ protected async instantiateWasm (
38
38
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
39
39
imports : any ,
40
40
success : ( instance : WebAssembly . Instance , module : WebAssembly . Module ) => void ,
@@ -89,15 +89,53 @@ export abstract class DuckDBBrowserBindings extends DuckDBBindingsBase {
89
89
} ;
90
90
// Instantiate streaming
91
91
const response = fetchWithProgress ( ) ;
92
- WebAssembly . instantiateStreaming ( response , imports ) . then ( output => {
93
- success ( output . instance , output . module ) ;
94
- } ) ;
92
+
93
+ const initiateStreaming = async ( ) => {
94
+ try {
95
+ const output = await WebAssembly . instantiateStreaming ( response , imports ) ;
96
+ success ( output . instance , output . module ) ;
97
+
98
+ } catch ( error : any ) {
99
+ this . logger . log ( {
100
+ timestamp : new Date ( ) ,
101
+ level : LogLevel . ERROR ,
102
+ origin : LogOrigin . BINDINGS ,
103
+ topic : LogTopic . INSTANTIATE ,
104
+ event : LogEvent . ERROR ,
105
+ value : 'Failed to instantiate WASM: ' + error ,
106
+ } ) ;
107
+
108
+ throw error ;
109
+ }
110
+ } ;
111
+
112
+ await initiateStreaming ( ) ;
113
+
95
114
} else {
96
115
console . warn ( 'instantiating without progress handler since transform streams are unavailable' ) ;
97
116
const request = new Request ( this . mainModuleURL ) ;
98
- WebAssembly . instantiateStreaming ( fetch ( request ) , imports ) . then ( output => {
99
- success ( output . instance , output . module ) ;
100
- } ) ;
117
+
118
+ const initiateStreaming = async ( ) => {
119
+ try {
120
+ const output = await WebAssembly . instantiateStreaming ( fetch ( request ) , imports ) ;
121
+ success ( output . instance , output . module ) ;
122
+
123
+ } catch ( error : any ) {
124
+ this . logger . log ( {
125
+ timestamp : new Date ( ) ,
126
+ level : LogLevel . ERROR ,
127
+ origin : LogOrigin . BINDINGS ,
128
+ topic : LogTopic . INSTANTIATE ,
129
+ event : LogEvent . ERROR ,
130
+ value : 'Failed to instantiate WASM: ' + error ,
131
+ } ) ;
132
+
133
+ throw error ;
134
+ }
135
+ } ;
136
+
137
+ await initiateStreaming ( ) ;
138
+
101
139
}
102
140
} else if ( typeof XMLHttpRequest == 'function' ) {
103
141
// Otherwise we fall back to XHRs
0 commit comments