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

@ -495,7 +495,7 @@ mod tests {
let listen_addr = async_std::task::block_on(async {
loop {
let swarm1_fut = swarm1.next_event();
let swarm1_fut = swarm1.select_next_some();
pin_mut!(swarm1_fut);
match swarm1_fut.await {
SwarmEvent::NewListenAddr(addr) => return addr,
@ -511,13 +511,16 @@ mod tests {
// either `Identified` event arrives correctly.
async_std::task::block_on(async move {
loop {
let swarm1_fut = swarm1.next();
let swarm1_fut = swarm1.select_next_some();
pin_mut!(swarm1_fut);
let swarm2_fut = swarm2.next();
let swarm2_fut = swarm2.select_next_some();
pin_mut!(swarm2_fut);
match future::select(swarm1_fut, swarm2_fut).await.factor_second().0 {
future::Either::Left(IdentifyEvent::Received { info, .. }) => {
future::Either::Left(SwarmEvent::Behaviour(IdentifyEvent::Received {
info,
..
})) => {
assert_eq!(info.public_key, pubkey2);
assert_eq!(info.protocol_version, "c");
assert_eq!(info.agent_version, "d");
@ -525,7 +528,10 @@ mod tests {
assert!(info.listen_addrs.is_empty());
return;
}
future::Either::Right(IdentifyEvent::Received { info, .. }) => {
future::Either::Right(SwarmEvent::Behaviour(IdentifyEvent::Received {
info,
..
})) => {
assert_eq!(info.public_key, pubkey1);
assert_eq!(info.protocol_version, "a");
assert_eq!(info.agent_version, "b");
@ -568,7 +574,7 @@ mod tests {
let listen_addr = async_std::task::block_on(async {
loop {
let swarm1_fut = swarm1.next_event();
let swarm1_fut = swarm1.select_next_some();
pin_mut!(swarm1_fut);
match swarm1_fut.await {
SwarmEvent::NewListenAddr(addr) => return addr,
@ -581,8 +587,8 @@ mod tests {
async_std::task::block_on(async move {
loop {
let swarm1_fut = swarm1.next_event();
let swarm2_fut = swarm2.next_event();
let swarm1_fut = swarm1.select_next_some();
let swarm2_fut = swarm2.select_next_some();
{
pin_mut!(swarm1_fut);