Skip to content

Commit 8c1a88b

Browse files
authored
Remove the futures dependencies (#468)
* No longer use futures::lock::Mutex * Directly use the `futures-channel` dependency for channels * Use futures-util::select! instead of futures::select! * Import from futures_util rather than futures::prelude * Forgot one usage of futures::lock * Revert accidental usage of async_executor * Final clean-ups
1 parent e215e69 commit 8c1a88b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+142
-116
lines changed

Cargo.lock

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

full-node/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ path = "src/main.rs"
1515

1616
[dependencies]
1717
async-std = "1.12.0"
18+
async-lock = { version = "2.7.0" }
1819
atty = "0.2.14"
1920
blake2-rfc = { version = "0.2.18", default-features = false }
2021
clap = { version = "4.2.4", default-features = false, features = ["color", "derive", "help", "std", "suggestions", "usage"] } # Note: enabling/disabling some features modifies the internal behavior of clap, be careful
@@ -25,8 +26,10 @@ either = { version = "1.8.1", default-features = false }
2526
env_logger = { version = "0.10.0", default-features = false, features = ["auto-color", "humantime"] }
2627
event-listener = { version = "2.5.3" }
2728
fnv = { version = "1.0.7", default-features = false }
28-
futures = { version = "0.3.27", default-features = false, features = ["std", "thread-pool"] }
29+
futures-channel = "0.3.27"
30+
futures-executor = { version = "0.3.28", default-features = false, features = ["std", "thread-pool"] }
2931
futures-timer = "3.0"
32+
futures-util = { version = "0.3.27", default-features = false }
3033
hashbrown = { version = "0.13.2", default-features = false }
3134
hex = { version = "0.4.3", default-features = false }
3235
log = { version = "0.4.17", default-features = false }

full-node/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod cli;
2222
mod run;
2323

2424
fn main() {
25-
futures::executor::block_on(async_main())
25+
futures_executor::block_on(async_main())
2626
}
2727

2828
async fn async_main() {

full-node/src/run.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
use crate::cli;
1919

20-
use futures::{channel::oneshot, prelude::*};
20+
use futures_channel::oneshot;
21+
use futures_util::{future, stream, FutureExt as _, StreamExt as _};
2122
use smoldot::{
2223
chain, chain_spec,
2324
database::full_sqlite,
@@ -189,7 +190,7 @@ pub async fn run(cli_options: cli::CliOptionsRun) {
189190
.as_ref()
190191
.map(|relay_chain_spec| relay_chain_spec.as_chain_information().unwrap().0);
191192

192-
let threads_pool = futures::executor::ThreadPool::builder()
193+
let threads_pool = futures_executor::ThreadPool::builder()
193194
.name_prefix("tasks-pool-")
194195
.create()
195196
.unwrap();
@@ -592,7 +593,7 @@ pub async fn run(cli_options: cli::CliOptionsRun) {
592593
debug_assert!(network_events_receivers.next().is_none());
593594

594595
loop {
595-
futures::select! {
596+
futures_util::select! {
596597
_ = informant_timer.next() => {
597598
if matches!(cli_output, cli::Output::Informant) {
598599
// We end the informant line with a `\r` so that it overwrites itself every time.
@@ -826,7 +827,7 @@ async fn background_open_database(
826827
let mut next_progress_icon = ['-', '\\', '|', '/'].iter().copied().cycle();
827828

828829
loop {
829-
futures::select! {
830+
futures_util::select! {
830831
res = rx => return res.unwrap(),
831832
_ = progress_timer.next() => {
832833
if show_progress {

full-node/src/run/consensus_service.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626

2727
use crate::run::{database_thread, jaeger_service, network_service};
2828

29+
use async_lock::Mutex;
2930
use core::{num::NonZeroU32, ops};
30-
use futures::{lock::Mutex, prelude::*};
31+
use futures_util::{future, stream, FutureExt as _, StreamExt as _};
3132
use hashbrown::HashSet;
3233
use smoldot::{
3334
author,
@@ -495,7 +496,7 @@ impl SyncBackground {
495496
}
496497
};
497498

498-
futures::select! {
499+
futures_util::select! {
499500
() = authoring_ready_future => {
500501
// Ready to author a block. Call `author_block()`.
501502
// While a block is being authored, the whole syncing state machine is

full-node/src/run/database_thread.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
//! As explained in the documentation of smoldot, the database uses synchronous I/O operations.
1919
//! For this reason, it is undesirable to access it from an asynchronous context.
2020
21-
use futures::{
22-
channel::{mpsc, oneshot},
23-
lock::Mutex,
24-
prelude::*,
25-
};
21+
use async_lock::Mutex;
22+
use futures_channel::{mpsc, oneshot};
23+
use futures_util::{SinkExt as _, StreamExt as _};
2624
use smoldot::database::full_sqlite::SqliteFullDatabase;
2725
use std::thread;
2826

@@ -82,7 +80,7 @@ impl From<SqliteFullDatabase> for DatabaseThread {
8280
.spawn(move || {
8381
// When the `DatabaseThread` is dropped, the sender will close, `rx.next()`
8482
// will return `None`, and the closure here will finish, ending the thread.
85-
while let Some(closure) = futures::executor::block_on(rx.next()) {
83+
while let Some(closure) = futures_executor::block_on(rx.next()) {
8684
closure(&db)
8785
}
8886
})

full-node/src/run/jaeger_service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
// TODO: more documentation
3636

3737
use async_std::net::UdpSocket;
38-
use futures::prelude::*;
38+
use futures_util::future;
3939
use smoldot::libp2p::PeerId;
4040
use std::{convert::TryFrom as _, io, net::SocketAddr, num::NonZeroU128, sync::Arc};
4141

full-node/src/run/json_rpc_service.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18-
use futures::{channel::oneshot, prelude::*};
18+
use futures_channel::oneshot;
19+
use futures_util::{future, FutureExt as _};
1920
use smoldot::json_rpc::{self, methods, websocket_server};
2021
use std::{io, net::SocketAddr};
2122

@@ -93,7 +94,7 @@ struct JsonRpcBackground {
9394
impl JsonRpcBackground {
9495
async fn run(mut self) {
9596
loop {
96-
let event = futures::select! {
97+
let event = futures_util::select! {
9798
_ = &mut self.client_still_alive => return,
9899
event = self.server.next_event().fuse() => event,
99100
};

full-node/src/run/network_service.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929

3030
use crate::run::{database_thread, jaeger_service};
3131

32-
use core::{cmp, mem, task::Poll, time::Duration};
33-
use futures::{
34-
channel::{mpsc, oneshot},
35-
lock::Mutex,
36-
prelude::*,
37-
};
32+
use async_lock::Mutex;
33+
use core::{cmp, future::Future, mem, task::Poll, time::Duration};
34+
use futures_channel::{mpsc, oneshot};
35+
use futures_util::{future, stream, FutureExt as _, SinkExt as _, StreamExt as _};
3836
use hashbrown::HashMap;
3937
use smoldot::{
4038
database::full_sqlite,
@@ -462,7 +460,7 @@ impl NetworkService {
462460
let future = async move {
463461
let mut connections = stream::FuturesUnordered::new();
464462
loop {
465-
futures::select! {
463+
futures_util::select! {
466464
new_connec = conn_tasks_rx.select_next_some() => {
467465
connections.push(new_connec);
468466
},

full-node/src/run/network_service/tasks.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
use super::Inner;
1919

20-
use core::{pin, time::Duration};
21-
use futures::{channel::mpsc, prelude::*};
20+
use core::{future::Future, pin, time::Duration};
21+
use futures_channel::mpsc;
2222
use futures_timer::Delay;
23+
use futures_util::{future, AsyncRead, AsyncWrite, FutureExt as _, StreamExt as _};
2324
use smoldot::{
2425
libp2p::{
2526
async_std_connection::with_buffers,
@@ -74,7 +75,7 @@ pub(super) async fn opening_connection_task(
7475
})
7576
.fuse();
7677
let mut socket = pin::pin!(socket.fuse());
77-
futures::select! {
78+
futures_util::select! {
7879
_ = timeout => {
7980
let mut guarded = inner.guarded.lock().await;
8081
guarded.num_pending_out_attempts -= 1;
@@ -247,7 +248,7 @@ pub(super) async fn established_connection_task(
247248
// always remain ready until we push an element. While waiting, we process
248249
// incoming messages.
249250
loop {
250-
futures::select! {
251+
futures_util::select! {
251252
_ = future::poll_fn(|cx| connection_to_coordinator.poll_ready(cx)).fuse() => break,
252253
message = coordinator_to_connection.next() => {
253254
if let Some(message) = message {

0 commit comments

Comments
 (0)