@@ -5,7 +5,7 @@ use crate::client::{
55use crate :: error:: RpcIntErr ;
66use captains_log:: filter:: LogFilter ;
77use crossfire:: { MAsyncRx , MAsyncTx , MTx , RecvTimeoutError , mpmc} ;
8- use orb:: AsyncRuntime ;
8+ use orb:: prelude :: { AsyncExec , AsyncTime } ;
99use std:: fmt;
1010use std:: marker:: PhantomData ;
1111use std:: sync:: Arc ;
@@ -65,9 +65,7 @@ struct ConnPoolInner<F: ClientFacts, P: ClientTransport> {
6565const ONE_SEC : Duration = Duration :: from_secs ( 1 ) ;
6666
6767impl < F : ClientFacts , P : ClientTransport > ConnPool < F , P > {
68- pub fn new < RT : AsyncRuntime + Clone > (
69- facts : Arc < F > , rt : & RT , addr : & str , mut channel_size : usize ,
70- ) -> Self {
68+ pub fn new ( facts : Arc < F > , rt : & P :: RT , addr : & str , mut channel_size : usize ) -> Self {
7169 let config = facts. get_config ( ) ;
7270 if config. thresholds > 0 {
7371 if channel_size < config. thresholds {
@@ -91,7 +89,7 @@ impl<F: ClientFacts, P: ClientTransport> ConnPool<F, P> {
9189 _phan : Default :: default ( ) ,
9290 } ) ;
9391 let s = Self { tx_async, tx, inner } ;
94- s. spawn :: < RT > ( rt) ;
92+ s. spawn ( rt) ;
9593 s
9694 }
9795
@@ -118,7 +116,7 @@ impl<F: ClientFacts, P: ClientTransport> ConnPool<F, P> {
118116 /// by default there's one worker thread after initiation, but you can pre-spawn more thread if
119117 /// the connection is not enough to achieve desired throughput.
120118 #[ inline]
121- pub fn spawn < RT : AsyncRuntime + Clone > ( & self , rt : & RT ) {
119+ pub fn spawn ( & self , rt : & P :: RT ) {
122120 let worker_id = self . inner . worker_count . fetch_add ( 1 , Acquire ) ;
123121 self . inner . clone ( ) . spawn_worker ( rt, worker_id) ;
124122 }
@@ -155,7 +153,7 @@ impl<F: ClientFacts, P: ClientTransport> fmt::Display for ConnPoolInner<F, P> {
155153}
156154
157155impl < F : ClientFacts , P : ClientTransport > ConnPoolInner < F , P > {
158- fn spawn_worker < RT : AsyncRuntime + Clone > ( self : Arc < Self > , rt : & RT , worker_id : usize ) {
156+ fn spawn_worker ( self : Arc < Self > , rt : & P :: RT , worker_id : usize ) {
159157 let _rt = rt. clone ( ) ;
160158 rt. spawn_detach ( async move {
161159 logger_trace ! ( & self . logger, "{} worker_id={} running" , self , worker_id) ;
@@ -181,7 +179,7 @@ impl<F: ClientFacts, P: ClientTransport> ConnPoolInner<F, P> {
181179 }
182180
183181 #[ inline]
184- async fn connect < RT : AsyncRuntime > ( & self , rt : & RT ) -> Result < ClientStream < F , P > , RpcIntErr > {
182+ async fn connect ( & self , rt : & P :: RT ) -> Result < ClientStream < F , P > , RpcIntErr > {
185183 ClientStream :: connect ( self . facts . clone ( ) , rt, & self . addr , & self . conn_id , None ) . await
186184 }
187185
@@ -220,23 +218,27 @@ impl<F: ClientFacts, P: ClientTransport> ConnPoolInner<F, P> {
220218 /// connection attempts happens after we spawn.
221219 /// If the address is dead, the thread might exit after multiple attempts, and later re-spawn
222220 /// when the needs arrives.
223- async fn run < RT : AsyncRuntime + Clone > ( self : & Arc < Self > , rt : RT , mut worker_id : usize ) {
221+ async fn run ( self : & Arc < Self > , rt : P :: RT , mut worker_id : usize ) {
224222 ' CONN_LOOP : loop {
225- match self . connect :: < RT > ( & rt) . await {
223+ match self . connect ( & rt) . await {
226224 Ok ( mut stream) => {
227225 logger_trace ! ( self . logger, "{} worker={} connected" , self , worker_id) ;
228226 if worker_id == 0 {
229227 // act as monitor
230228 ' MONITOR : loop {
231229 if self . get_workers ( ) > 1 {
232- RT :: sleep ( ONE_SEC ) . await ;
230+ < P :: RT as AsyncTime > :: sleep ( ONE_SEC ) . await ;
233231 if stream. ping ( ) . await . is_err ( ) {
234232 self . set_err ( ) ;
235233 // don't cleanup the channel unless only one worker left
236234 continue ' CONN_LOOP ;
237235 }
238236 } else {
239- match self . rx . recv_with_timer ( RT :: sleep ( ONE_SEC ) ) . await {
237+ match self
238+ . rx
239+ . recv_with_timer ( <P :: RT as AsyncTime >:: sleep ( ONE_SEC ) )
240+ . await
241+ {
240242 Err ( RecvTimeoutError :: Disconnected ) => {
241243 return ;
242244 }
@@ -258,13 +260,13 @@ impl<F: ClientFacts, P: ClientTransport> ConnPoolInner<F, P> {
258260 // there's might be a lag to connect,
259261 // so we are spawning identity with new worker,
260262 worker_id = 1 ;
261- self . clone ( ) . spawn_worker :: < RT > ( & rt, 0 ) ;
263+ self . clone ( ) . spawn_worker ( & rt, 0 ) ;
262264 }
263265 if stream. send_task ( task, true ) . await . is_err ( ) {
264266 self . set_err ( ) ;
265267 if worker_id == 0 {
266268 self . cleanup ( ) ;
267- RT :: sleep ( ONE_SEC ) . await ;
269+ < P :: RT as AsyncTime > :: sleep ( ONE_SEC ) . await ;
268270 continue ' CONN_LOOP ;
269271 } else {
270272 return ;
@@ -297,7 +299,7 @@ impl<F: ClientFacts, P: ClientTransport> ConnPoolInner<F, P> {
297299 self . set_err ( ) ;
298300 error ! ( "connect failed to {}: {}" , self . addr, e) ;
299301 self . cleanup ( ) ;
300- RT :: sleep ( ONE_SEC ) . await ;
302+ < P :: RT as AsyncTime > :: sleep ( ONE_SEC ) . await ;
301303 }
302304 }
303305 }
0 commit comments