@@ -6,7 +6,9 @@ use std::thread::sleep;
6
6
use std:: time:: Duration ;
7
7
8
8
use async_h1:: client;
9
+ use async_std:: future:: timeout;
9
10
use async_std:: net:: TcpStream ;
11
+ use async_std:: task;
10
12
use clarity:: vm:: analysis:: contract_interface_builder:: build_contract_interface;
11
13
use clarity:: vm:: costs:: ExecutionCost ;
12
14
use clarity:: vm:: events:: { FTEventType , NFTEventType , STXEventType } ;
@@ -326,26 +328,24 @@ impl EventObserver {
326
328
req. append_header ( "Content-Type" , "application/json" ) ;
327
329
req. set_body ( body) ;
328
330
329
- let response = async_std:: task:: block_on ( async {
330
- match async_std:: future:: timeout (
331
- connection_timeout,
332
- TcpStream :: connect ( self . endpoint . clone ( ) ) ,
333
- )
334
- . await
335
- {
336
- Ok ( Ok ( stream) ) => match client:: connect ( stream, req) . await {
337
- Ok ( response) => Some ( response) ,
338
- Err ( err) => {
339
- warn ! ( "Event dispatcher: rpc invocation failed - {:?}" , err) ;
340
- None
331
+ let response = task:: block_on ( async {
332
+ let stream =
333
+ match timeout ( connection_timeout, TcpStream :: connect ( & self . endpoint ) ) . await {
334
+ Ok ( Ok ( stream) ) => stream,
335
+ Ok ( Err ( err) ) => {
336
+ warn ! ( "Event dispatcher: connection failed - {:?}" , err) ;
337
+ return None ;
341
338
}
342
- } ,
343
- Ok ( Err ( err) ) => {
344
- warn ! ( "Event dispatcher: connection failed - {:?}" , err) ;
345
- None
346
- }
347
- Err ( _) => {
348
- error ! ( "Event dispatcher: connection attempt timed out" ) ;
339
+ Err ( _) => {
340
+ error ! ( "Event dispatcher: connection attempt timed out" ) ;
341
+ return None ;
342
+ }
343
+ } ;
344
+
345
+ match client:: connect ( stream, req) . await {
346
+ Ok ( response) => Some ( response) ,
347
+ Err ( err) => {
348
+ warn ! ( "Event dispatcher: rpc invocation failed - {:?}" , err) ;
349
349
None
350
350
}
351
351
}
0 commit comments