@@ -138,46 +138,41 @@ export function getRpcClient(
138
138
requestTimeoutMs : options . config ?. requestTimeoutMs ,
139
139
} )
140
140
. then ( ( responses ) => {
141
- // for each response, resolve the inflight request
142
141
activeBatch . forEach ( ( inflight , index ) => {
142
+ // Handle the inflight request promise for each response.
143
143
const response = responses [ index ] ;
144
- // if we didn't get a response at all, reject the inflight request
144
+
145
+ // No response.
145
146
if ( ! response ) {
146
147
inflight . reject ( new Error ( "No response" ) ) ;
147
- return ;
148
148
}
149
- // handle errors in the response
150
- if ( response instanceof Error ) {
149
+ // Response is an error or error string.
150
+ else if ( response instanceof Error ) {
151
151
inflight . reject ( response ) ;
152
- return ;
153
- }
154
-
155
- // handle strings as responses??
156
- if ( typeof response === "string" ) {
152
+ } else if ( "error" in response ) {
153
+ inflight . reject ( response . error ) ;
154
+ } else if ( typeof response === "string" ) {
157
155
inflight . reject ( new Error ( response ) ) ;
158
- return ;
159
156
}
160
-
161
- if ( "error" in response ) {
162
- inflight . reject ( response . error ) ;
163
- // otherwise, resolve the inflight request
164
- } else if ( response . method === "eth_subscription" ) {
165
- // TODO: handle subscription responses
166
- throw new Error ( "Subscriptions not supported yet" ) ;
167
- } else {
157
+ // eth_subscription is not supported yet.
158
+ else if ( response . method === "eth_subscription" ) {
159
+ inflight . reject ( "Subscriptions not supported yet" ) ;
160
+ }
161
+ // Else return the successful response for the inflight request.
162
+ else {
168
163
inflight . resolve ( response . result ) ;
169
164
}
170
- // remove the inflight request from the inflightRequests map
171
- inflightRequests . delete ( inflight . requestKey ) ;
172
165
} ) ;
173
166
} )
174
167
. catch ( ( err ) => {
175
168
// http call failed, reject all inflight requests
176
169
for ( const inflight of activeBatch ) {
177
170
inflight . reject ( err ) ;
178
- // remove the inflight request from the inflightRequests map
179
- inflightRequests . delete ( inflight . requestKey ) ;
180
171
}
172
+ } )
173
+ . finally ( ( ) => {
174
+ // Clear the inflight requests map so any new requests are re-fetched.
175
+ inflightRequests . clear ( ) ;
181
176
} ) ;
182
177
}
183
178
0 commit comments