@@ -38,7 +38,7 @@ use std::sync::Arc;
3838use std:: sync:: mpsc as sync_mpsc;
3939use std:: thread;
4040use std:: time:: { Duration , Instant } ;
41- use futures:: { future, Future , stream, Stream } ;
41+ use futures:: { future, Future , stream, Stream , select_all } ;
4242use futures:: sync:: { mpsc, oneshot} ;
4343use tokio:: runtime:: current_thread;
4444use tokio_io:: { AsyncRead , AsyncWrite } ;
@@ -546,19 +546,24 @@ fn init_thread(
546546 // Start the process of pinging the active nodes on the network.
547547 let periodic = start_periodic_updates ( shared. clone ( ) , transport, swarm_controller) ;
548548
549- // Merge all the futures into one!
550- Ok ( swarm_events. for_each ( |_| Ok ( ( ) ) )
551- . select ( discovery) . map_err ( |( err, _) | err) . and_then ( |( _, rest) | rest)
552- . select ( periodic) . map_err ( |( err, _) | err) . and_then ( |( _, rest) | rest)
553- . select ( outgoing_connections) . map_err ( |( err, _) | err) . and_then ( |( _, rest) | rest)
554- . select ( timeouts) . map_err ( |( err, _) | err) . and_then ( |( _, rest) | rest)
555- . select ( close_rx. then ( |_| Ok ( ( ) ) ) ) . map ( |_| ( ) ) . map_err ( |( err, _) | err)
556-
549+ let futures: Vec < Box < Future < Item =( ) , Error =IoError > > > = vec ! [
550+ Box :: new( swarm_events. for_each( |_| Ok ( ( ) ) ) ) ,
551+ Box :: new( discovery) ,
552+ Box :: new( periodic) ,
553+ Box :: new( outgoing_connections) ,
554+ Box :: new( timeouts) ,
555+ Box :: new( close_rx. map_err( |err| IoError :: new( IoErrorKind :: Other , err) ) ) ,
556+ ] ;
557+
558+ Ok (
559+ select_all ( futures. into_iter ( ) )
557560 . and_then ( move |_| {
558561 debug ! ( target: "sub-libp2p" , "Networking ended ; disconnecting all peers" ) ;
559562 shared. network_state . disconnect_all ( ) ;
560563 Ok ( ( ) )
561- } ) )
564+ } )
565+ . map_err ( |( r, _, _) | r)
566+ )
562567}
563568
564569/// Output of the common transport layer.
0 commit comments