Skip to content

Commit

Permalink
refactor(examples): change file-sharing from async-std to tokio
Browse files Browse the repository at this point in the history
Closes: #5180
Related: #4449.

Pull-Request: #5191.
  • Loading branch information
bklaing2 authored and guillaumemichel committed Mar 28, 2024
1 parent 72feac1 commit bbfac65
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions examples/file-sharing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ release = false

[dependencies]
serde = { version = "1.0", features = ["derive"] }
async-std = { version = "1.12", features = ["attributes"] }
tokio = { version = "1.36.0", features = ["full"] }
clap = { version = "4.4.16", features = ["derive"] }
either = "1.9"
futures = "0.3.30"
libp2p = { path = "../../libp2p", features = [ "async-std", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] }
libp2p = { path = "../../libp2p", features = [ "tokio", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
void = "1.0.2"
Expand Down
4 changes: 2 additions & 2 deletions examples/file-sharing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

mod network;

use async_std::task::spawn;
use clap::Parser;
use tokio::task::spawn;

use futures::prelude::*;
use futures::StreamExt;
Expand All @@ -33,7 +33,7 @@ use std::io::Write;
use std::path::PathBuf;
use tracing_subscriber::EnvFilter;

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
Expand Down
7 changes: 4 additions & 3 deletions examples/file-sharing/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use futures::channel::{mpsc, oneshot};
use futures::prelude::*;
use futures::StreamExt;

use libp2p::{
core::Multiaddr,
Expand Down Expand Up @@ -40,7 +41,7 @@ pub(crate) async fn new(
let peer_id = id_keys.public().to_peer_id();

let mut swarm = libp2p::SwarmBuilder::with_existing_identity(id_keys)
.with_async_std()
.with_tokio()
.with_tcp(
tcp::Config::default(),
noise::Config::new,
Expand Down Expand Up @@ -197,8 +198,8 @@ impl EventLoop {

pub(crate) async fn run(mut self) {
loop {
futures::select! {
event = self.swarm.next() => self.handle_event(event.expect("Swarm stream to be infinite.")).await ,
tokio::select! {
event = self.swarm.select_next_some() => self.handle_event(event).await,
command = self.command_receiver.next() => match command {
Some(c) => self.handle_command(c).await,
// Command channel closed, thus shutting down the network event loop.
Expand Down

0 comments on commit bbfac65

Please sign in to comment.