File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
protosocket-rpc/src/client Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,16 @@ impl<Connector: ClientConnector> ConnectionPool<Connector> {
6161 }
6262 }
6363
64+ /// Get a consistent connection from the pool for a given key.
65+ pub async fn get_connection_for_key (
66+ & self ,
67+ key : usize ,
68+ ) -> crate :: Result < RpcClient < Connector :: Request , Connector :: Response > > {
69+ let slot = key % self . connections . len ( ) ;
70+
71+ self . get_connection_by_slot ( slot) . await
72+ }
73+
6474 /// Get a connection from the pool.
6575 pub async fn get_connection (
6676 & self ,
@@ -72,6 +82,14 @@ impl<Connector: ClientConnector> ConnectionPool<Connector> {
7282 // Safety: This is executed on a thread, in only one place. It cannot be borrowed anywhere else.
7383 let slot = THREAD_LOCAL_SMALL_RANDOM
7484 . with_borrow_mut ( |rng| rng. random_range ( 0 ..self . connections . len ( ) ) ) ;
85+
86+ self . get_connection_by_slot ( slot) . await
87+ }
88+
89+ async fn get_connection_by_slot (
90+ & self ,
91+ slot : usize ,
92+ ) -> crate :: Result < RpcClient < Connector :: Request , Connector :: Response > > {
7593 let connection_state = & self . connections [ slot] ;
7694
7795 // The connection state requires a mutex, so I need to keep await out of the scope to satisfy clippy (and for paranoia).
You can’t perform that action at this time.
0 commit comments