@@ -138,46 +138,41 @@ export function getRpcClient(
138138 requestTimeoutMs : options . config ?. requestTimeoutMs ,
139139 } )
140140 . then ( ( responses ) => {
141- // for each response, resolve the inflight request
142141 activeBatch . forEach ( ( inflight , index ) => {
142+ // Handle the inflight request promise for each response.
143143 const response = responses [ index ] ;
144- // if we didn't get a response at all, reject the inflight request
144+
145+ // No response.
145146 if ( ! response ) {
146147 inflight . reject ( new Error ( "No response" ) ) ;
147- return ;
148148 }
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 ) {
151151 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" ) {
157155 inflight . reject ( new Error ( response ) ) ;
158- return ;
159156 }
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 {
168163 inflight . resolve ( response . result ) ;
169164 }
170- // remove the inflight request from the inflightRequests map
171- inflightRequests . delete ( inflight . requestKey ) ;
172165 } ) ;
173166 } )
174167 . catch ( ( err ) => {
175168 // http call failed, reject all inflight requests
176169 for ( const inflight of activeBatch ) {
177170 inflight . reject ( err ) ;
178- // remove the inflight request from the inflightRequests map
179- inflightRequests . delete ( inflight . requestKey ) ;
180171 }
172+ } )
173+ . finally ( ( ) => {
174+ // Clear the inflight requests map so any new requests are re-fetched.
175+ inflightRequests . clear ( ) ;
181176 } ) ;
182177 }
183178
0 commit comments