swarm/: Drive ExpandedSwarm via Stream trait only (#2100)

Change `Stream` implementation of `ExpandedSwarm` to return all
`SwarmEvents` instead of only the `NetworkBehaviour`'s events.

Remove `ExpandedSwarm::next_event`. Users can use `<ExpandedSwarm as
StreamExt>::next` instead.

Remove `ExpandedSwarm::next`. Users can use `<ExpandedSwarm as
StreamExt>::filter_map` instead.
This commit is contained in:
Elena Frank
2021-06-14 20:41:44 +02:00
committed by GitHub
parent d45606ac97
commit e8fed53598
20 changed files with 340 additions and 331 deletions

View File

@ -262,7 +262,7 @@
//! use futures::executor::block_on;
//! use futures::prelude::*;
//! use libp2p::ping::{Ping, PingConfig};
//! use libp2p::swarm::Swarm;
//! use libp2p::swarm::{Swarm, SwarmEvent};
//! use libp2p::{identity, PeerId};
//! use std::error::Error;
//! use std::task::Poll;
@ -295,20 +295,15 @@
//! println!("Dialed {}", addr)
//! }
//!
//! let mut listening = false;
//! block_on(future::poll_fn(move |cx| loop {
//! match swarm.poll_next_unpin(cx) {
//! Poll::Ready(Some(event)) => println!("{:?}", event),
//! Poll::Ready(None) => return Poll::Ready(()),
//! Poll::Pending => {
//! if !listening {
//! for addr in Swarm::listeners(&swarm) {
//! println!("Listening on {}", addr);
//! listening = true;
//! }
//! Poll::Ready(Some(event)) => {
//! if let SwarmEvent::NewListenAddr(addr) = event {
//! println!("Listening on {:?}", addr);
//! }
//! return Poll::Pending;
//! }
//! },
//! Poll::Ready(None) => return Poll::Ready(()),
//! Poll::Pending => return Poll::Pending
//! }
//! }));
//!