@@ -3,7 +3,7 @@ import type { InterfaceAbi } from 'ethers'
3
3
import { Interface , WebSocketProvider , ethers } from 'ethers'
4
4
import { WebSocket } from 'ws'
5
5
import type { ErrorEvent } from 'ws'
6
- import { type ContractAddress , isInstanceof , to } from '@ora-io/utils'
6
+ import { type ContractAddress , isInstanceof , timeout , to } from '@ora-io/utils'
7
7
import { debug } from '../debug'
8
8
import { RekuContractManager } from './contract'
9
9
@@ -217,18 +217,14 @@ export class RekuProviderManager {
217
217
debug ( 'heartbeat running...' )
218
218
const hasProvider = this . _hasProvider ( )
219
219
debug ( 'heartbeat has provider: %s' , hasProvider )
220
- this . _provider ?. send ( 'net_version' , [ ] )
221
- . then ( ( res ) => {
222
- debug ( 'heartbeat response: %s' , res )
223
- } )
224
- . catch ( ( err ) => {
225
- this . reconnect ( )
226
- this . _event ?. emit ( 'error' , err )
227
- debug ( 'heartbeat error: %s' , err )
228
- } )
229
- . finally ( ( ) => {
230
- debug ( 'heartbeat finally' )
231
- } )
220
+
221
+ const [ err , res ] = await to ( timeout ( async ( ) => this . _provider ?. send ( 'net_version' , [ ] ) , 10 * 1000 ) )
222
+ if ( err ) {
223
+ this . reconnect ( )
224
+ this . _event ?. emit ( 'error' , err )
225
+ debug ( 'heartbeat timeout error: %s' , err )
226
+ }
227
+ else { debug ( 'heartbeat response: %s' , res ) }
232
228
}
233
229
else {
234
230
debug ( 'heartbeat destroyed' )
0 commit comments