@@ -332,6 +332,44 @@ impl Connection {
332
332
. boxed ( )
333
333
}
334
334
335
+ fn close_gc ( self ) -> BoxFuture < Connection , Error > {
336
+ let mut messages = vec ! [ ] ;
337
+ while let Ok ( ( type_, name) ) = self . 0 . close_receiver . try_recv ( ) {
338
+ let mut buf = vec ! [ ] ;
339
+ frontend:: close ( type_, & name, & mut buf) . unwrap ( ) ; // this can only fail on bad names
340
+ messages. push ( buf) ;
341
+ }
342
+ if messages. is_empty ( ) {
343
+ return Ok ( self ) . into_future ( ) . boxed ( ) ;
344
+ }
345
+
346
+ let mut buf = vec ! [ ] ;
347
+ frontend:: sync ( & mut buf) ;
348
+ messages. push ( buf) ;
349
+ self . 0 . send_all ( futures:: stream:: iter ( messages. into_iter ( ) . map ( Ok :: < _ , io:: Error > ) ) )
350
+ . map_err ( Error :: Io )
351
+ . and_then ( |s| Connection ( s. 0 ) . finish_close_gc ( ) )
352
+ . boxed ( )
353
+ }
354
+
355
+ fn finish_close_gc ( self ) -> BoxFuture < Connection , Error > {
356
+ self . 0 . read ( )
357
+ . map_err ( Error :: Io )
358
+ . and_then ( |( m, s) | {
359
+ match m {
360
+ backend:: Message :: ReadyForQuery ( _) => {
361
+ Either :: A ( Ok ( Connection ( s) ) . into_future ( ) )
362
+ }
363
+ backend:: Message :: CloseComplete => Either :: B ( Connection ( s) . finish_close_gc ( ) ) ,
364
+ backend:: Message :: ErrorResponse ( body) => {
365
+ Either :: B ( Connection ( s) . ready_err ( body) )
366
+ }
367
+ _ => Either :: A ( Err ( bad_message ( ) ) . into_future ( ) ) ,
368
+ }
369
+ } )
370
+ . boxed ( )
371
+ }
372
+
335
373
fn ready_err < T > ( self , body : ErrorResponseBody < Vec < u8 > > ) -> BoxFuture < T , Error >
336
374
where T : ' static + Send
337
375
{
@@ -563,44 +601,6 @@ impl Connection {
563
601
. boxed ( )
564
602
}
565
603
566
- fn close_gc ( self ) -> BoxFuture < Connection , Error > {
567
- let mut messages = vec ! [ ] ;
568
- while let Ok ( ( type_, name) ) = self . 0 . close_receiver . try_recv ( ) {
569
- let mut buf = vec ! [ ] ;
570
- frontend:: close ( type_, & name, & mut buf) . unwrap ( ) ; // this can only fail on bad names
571
- messages. push ( buf) ;
572
- }
573
- if messages. is_empty ( ) {
574
- return Ok ( self ) . into_future ( ) . boxed ( ) ;
575
- }
576
-
577
- let mut buf = vec ! [ ] ;
578
- frontend:: sync ( & mut buf) ;
579
- messages. push ( buf) ;
580
- self . 0 . send_all ( futures:: stream:: iter ( messages. into_iter ( ) . map ( Ok :: < _ , io:: Error > ) ) )
581
- . map_err ( Error :: Io )
582
- . and_then ( |s| Connection ( s. 0 ) . finish_close_gc ( ) )
583
- . boxed ( )
584
- }
585
-
586
- fn finish_close_gc ( self ) -> BoxFuture < Connection , Error > {
587
- self . 0 . read ( )
588
- . map_err ( Error :: Io )
589
- . and_then ( |( m, s) | {
590
- match m {
591
- backend:: Message :: ReadyForQuery ( _) => {
592
- Either :: A ( Ok ( Connection ( s) ) . into_future ( ) )
593
- }
594
- backend:: Message :: CloseComplete => Either :: B ( Connection ( s) . finish_close_gc ( ) ) ,
595
- backend:: Message :: ErrorResponse ( body) => {
596
- Either :: B ( Connection ( s) . ready_err ( body) )
597
- }
598
- _ => Either :: A ( Err ( bad_message ( ) ) . into_future ( ) ) ,
599
- }
600
- } )
601
- . boxed ( )
602
- }
603
-
604
604
pub fn close ( self ) -> BoxFuture < ( ) , Error > {
605
605
let mut terminate = vec ! [ ] ;
606
606
frontend:: terminate ( & mut terminate) ;
0 commit comments