@@ -4,6 +4,7 @@ use crate::{
4
4
ToStatement , Transaction , TransactionBuilder ,
5
5
} ;
6
6
use std:: task:: Poll ;
7
+ use std:: time:: Duration ;
7
8
use tokio_postgres:: tls:: { MakeTlsConnect , TlsConnect } ;
8
9
use tokio_postgres:: types:: { BorrowToSql , ToSql , Type } ;
9
10
use tokio_postgres:: { Error , Row , SimpleQueryMessage , Socket } ;
@@ -414,8 +415,14 @@ impl Client {
414
415
}
415
416
416
417
/// Validates connection, timing out after specified duration.
417
- pub fn is_valid ( & mut self , timeout : std:: time:: Duration ) -> Result < ( ) , Error > {
418
- self . connection . block_on ( self . client . is_valid ( timeout) )
418
+ pub fn is_valid ( & mut self , timeout : Duration ) -> Result < ( ) , Error > {
419
+ let is_valid = Client :: is_valid_inner ( & self . client , timeout) ;
420
+ self . connection . block_on ( is_valid)
421
+ }
422
+
423
+ async fn is_valid_inner ( client : & tokio_postgres:: Client , timeout : Duration ) -> Result < ( ) , Error > {
424
+ let trivial_query = client. simple_query ( "" ) ;
425
+ tokio:: time:: timeout ( timeout, trivial_query) . await ?. map ( |_| ( ) )
419
426
}
420
427
421
428
/// Executes a sequence of SQL statements using the simple query protocol.
0 commit comments