@@ -56,7 +56,7 @@ impl ConnectionStatus {
5656 pub ( crate ) fn connection_resolver ( & self ) -> Option < PromiseResolver < Connection > > {
5757 let resolver = self . lock_inner ( ) . connection_resolver ( ) ;
5858 // We carry the Connection here to drop the lock() above before dropping the Connection
59- resolver. map ( |( _ , resolver, _connection) | resolver)
59+ resolver. map ( |( resolver, _connection) | resolver. resolver_in )
6060 }
6161
6262 pub ( crate ) fn connection_step_name ( & self ) -> Option < & ' static str > {
@@ -128,17 +128,34 @@ impl ConnectionStatus {
128128 }
129129}
130130
131+ pub ( crate ) struct ConnectionResolver {
132+ resolver_out : Option < PromiseResolver < ( ) > > ,
133+ resolver_in : PromiseResolver < Connection > ,
134+ }
135+
136+ impl ConnectionResolver {
137+ pub ( crate ) fn resolve ( & self , conn : Connection ) {
138+ self . resolver_in . resolve ( conn) ;
139+ }
140+
141+ fn reject ( & self , err : Error ) {
142+ if let Some ( resolver) = self . resolver_out . as_ref ( ) {
143+ resolver. reject ( err. clone ( ) ) ;
144+ }
145+ self . resolver_in . reject ( err) ;
146+ }
147+ }
148+
131149pub ( crate ) enum ConnectionStep {
132150 ProtocolHeader (
133- PromiseResolver < ( ) > ,
134- PromiseResolver < Connection > ,
151+ ConnectionResolver ,
135152 Connection ,
136153 Credentials ,
137154 SASLMechanism ,
138155 ConnectionProperties ,
139156 ) ,
140- StartOk ( PromiseResolver < Connection > , Connection , Credentials ) ,
141- Open ( PromiseResolver < Connection > ) ,
157+ StartOk ( ConnectionResolver , Connection , Credentials ) ,
158+ Open ( ConnectionResolver ) ,
142159}
143160
144161#[ derive( Clone , Copy , Debug , Default , PartialEq ) ]
@@ -201,8 +218,10 @@ impl Inner {
201218 ) -> Result < ( ) > {
202219 self . state = ConnectionState :: Connecting ;
203220 self . connection_step = Some ( ConnectionStep :: ProtocolHeader (
204- resolver_out,
205- resolver_in,
221+ ConnectionResolver {
222+ resolver_out : Some ( resolver_out) ,
223+ resolver_in,
224+ } ,
206225 conn,
207226 creds,
208227 mechanism,
@@ -218,23 +237,15 @@ impl Inner {
218237 self . blocked = false ;
219238 }
220239
221- fn connection_resolver (
222- & mut self ,
223- ) -> Option < (
224- Option < PromiseResolver < ( ) > > ,
225- PromiseResolver < Connection > ,
226- Option < Connection > ,
227- ) > {
240+ fn connection_resolver ( & mut self ) -> Option < ( ConnectionResolver , Option < Connection > ) > {
228241 self . connection_step
229242 . take ( )
230243 . map ( |connection_step| match connection_step {
231- ConnectionStep :: ProtocolHeader ( resolver_out, resolver_in, connection, ..) => {
232- ( Some ( resolver_out) , resolver_in, Some ( connection) )
233- }
234- ConnectionStep :: StartOk ( resolver, connection, ..) => {
235- ( None , resolver, Some ( connection) )
244+ ConnectionStep :: ProtocolHeader ( resolver, connection, ..) => {
245+ ( resolver, Some ( connection) )
236246 }
237- ConnectionStep :: Open ( resolver, ..) => ( None , resolver, None ) ,
247+ ConnectionStep :: StartOk ( resolver, connection, ..) => ( resolver, Some ( connection) ) ,
248+ ConnectionStep :: Open ( resolver, ..) => ( resolver, None ) ,
238249 } )
239250 }
240251
@@ -251,11 +262,8 @@ impl Inner {
251262 }
252263
253264 fn poison ( & mut self , err : Error ) {
254- if let Some ( ( resolver_out, resolver_in, _connection) ) = self . connection_resolver ( ) {
255- if let Some ( resolver) = resolver_out {
256- resolver. reject ( err. clone ( ) ) ;
257- }
258- resolver_in. reject ( err. clone ( ) ) ;
265+ if let Some ( ( resolver, _connection) ) = self . connection_resolver ( ) {
266+ resolver. reject ( err. clone ( ) ) ;
259267 }
260268 self . poison = Some ( err) ;
261269 }
0 commit comments