The SwarmFuture is now a Stream (#442)

* The SwarmFuture is now a Stream

* Return the produced future in the message

* Remove IncomingConnection event

* Pass error when failing to dial

* Fix loop break mistake

* Fix concern

* Rename SwarmFuture to SwarmEvents

* Increase type length limit

* Remove todo
This commit is contained in:
Pierre Krieger
2018-09-04 14:53:27 +02:00
committed by GitHub
parent ee9be6f0c9
commit 75ceba7809
11 changed files with 146 additions and 70 deletions

View File

@@ -133,6 +133,7 @@ fn main() {
// actually started yet. Because we created the `TcpConfig` with tokio, we need to run the
// future through the tokio core.
let final_future = swarm_future
.for_each(|_| Ok(()))
.select(finished_rx.map_err(|_| unreachable!()))
.map(|_| ())
.map_err(|(err, _)| err);

View File

@@ -141,5 +141,5 @@ fn main() {
// `swarm_future` is a future that contains all the behaviour that we want, but nothing has
// actually started yet. Because we created the `TcpConfig` with tokio, we need to run the
// future through the tokio core.
tokio_current_thread::block_on_all(swarm_future).unwrap();
tokio_current_thread::block_on_all(swarm_future.for_each(|_| Ok(()))).unwrap();
}

View File

@@ -149,6 +149,7 @@ fn main() {
};
let final_fut = swarm_future
.for_each(|_| Ok(()))
.select(floodsub_rx)
.map(|_| ())
.map_err(|e| e.0)

View File

@@ -18,7 +18,9 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#![type_length_limit = "2097152"]
// Libp2p's code unfortunately produces very large types. Rust's default length limit for type
// names is not large enough, therefore we need this attribute.
#![type_length_limit = "4194304"]
extern crate bigint;
extern crate bytes;
@@ -231,7 +233,7 @@ fn main() {
// future through the tokio core.
tokio_current_thread::block_on_all(
finish_enum
.select(swarm_future)
.select(swarm_future.for_each(|_| Ok(())))
.map(|(n, _)| n)
.map_err(|(err, _)| err),
).unwrap();

View File

@@ -25,7 +25,7 @@ extern crate libp2p;
extern crate tokio_current_thread;
extern crate tokio_io;
use futures::Future;
use futures::{Future, Stream};
use futures::sync::oneshot;
use std::env;
use libp2p::core::Transport;
@@ -112,7 +112,7 @@ fn main() {
// actually started yet. Because we created the `TcpConfig` with tokio, we need to run the
// future through the tokio core.
tokio_current_thread::block_on_all(
rx.select(swarm_future.map_err(|_| unreachable!()))
rx.select(swarm_future.for_each(|_| Ok(())).map_err(|_| unreachable!()))
.map_err(|(e, _)| e)
.map(|_| ()),
).unwrap();

View File

@@ -152,7 +152,7 @@ fn run_dialer(opts: DialerOpts) -> Result<(), Box<Error>> {
control.dial(address, transport.with_upgrade(echo)).map_err(|_| "failed to dial")?;
tokio_current_thread::block_on_all(future).map_err(From::from)
tokio_current_thread::block_on_all(future.for_each(|_| Ok(()))).map_err(From::from)
}
fn run_listener(opts: ListenerOpts) -> Result<(), Box<Error>> {
@@ -206,7 +206,7 @@ fn run_listener(opts: ListenerOpts) -> Result<(), Box<Error>> {
});
control.listen_on(opts.listen).map_err(|_| "failed to listen")?;
tokio_current_thread::block_on_all(future).map_err(From::from)
tokio_current_thread::block_on_all(future.for_each(|_| Ok(()))).map_err(From::from)
}
// Custom parsers ///////////////////////////////////////////////////////////