Skip to content

Commit

Permalink
refactor!: avoid using futures crate directly (#2117)
Browse files Browse the repository at this point in the history
Due to the low maintenance and absurd high amount of `unsafe` code in
parts of the `futures` crate, we are trying to avoid usage of it.

Usages are replaced with

- `futures-lite` : general `Future` and `Stream` tooling
- `futures-sink`: `Sink` trait
- `futures-buffered`: faster and safer version of `Futures{Un}Ordered`
- If must be `futures-util` for sink specific things that are missing

## Breaking Changes

- `iroh::node::Node` does not implement `Future` anymore
- `iroh::node::Node::shutdown()` is now `async` and can be awaited upon
to wait for the node to exit
- `iroh_net::util::AbortingJoinHandle`s inner field is not public
anymore, use the `From<JoinHandle>` implementation to contruct it


## Followups

- [x] Apply this to `bao-tree`:
n0-computer/bao-tree#49
- [x] Apply this to `iroh-io`:
n0-computer/iroh-io#6
- [x] Apply this to `quic-rpc`:
n0-computer/quic-rpc#73

---------

Co-authored-by: Ruediger Klaehn <rklaehn@protonmail.com>
  • Loading branch information
dignifiedquire and rklaehn authored Apr 29, 2024
1 parent 03d0fe5 commit 9f5ef8f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ iroh-metrics = { version = "0.14.0", path = "../iroh-metrics" }
iroh-base = { version = "0.14.0", path = "../iroh-base" }

# net dependencies (optional)
futures = { version = "0.3.25", optional = true }
futures-lite = { version = "2.3", optional = true }
iroh-net = { path = "../iroh-net", version = "0.14.0", optional = true, default-features = false }
quinn = { version = "0.10", optional = true }
tokio = { version = "1", optional = true, features = ["io-util", "sync", "rt", "macros", "net", "fs"] }
Expand All @@ -47,7 +47,7 @@ url = "2.4.0"

[features]
default = ["net"]
net = ["futures", "iroh-net", "quinn", "tokio", "tokio-util"]
net = ["dep:futures-lite", "dep:iroh-net", "dep:quinn", "dep:tokio", "dep:tokio-util"]

[[example]]
name = "chat"
Expand Down
6 changes: 3 additions & 3 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
use anyhow::{anyhow, Context};
use bytes::{Bytes, BytesMut};
use futures::{stream::Stream, FutureExt};
use futures_lite::stream::Stream;
use genawaiter::sync::{Co, Gen};
use iroh_net::{
dialer::Dialer, key::PublicKey, magic_endpoint::get_remote_node_id, AddrInfo, MagicEndpoint,
NodeAddr,
};
use rand::rngs::StdRng;
use rand_core::SeedableRng;
use std::{collections::HashMap, future::Future, sync::Arc, task::Poll, time::Instant};
use std::{collections::HashMap, future::Future, pin::Pin, sync::Arc, task::Poll, time::Instant};
use tokio::{
sync::{broadcast, mpsc, oneshot},
task::JoinHandle,
Expand Down Expand Up @@ -276,7 +276,7 @@ impl Future for JoinTopicFut {
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
let res = self.0.poll_unpin(cx);
let res = Pin::new(&mut self.0).poll(cx);
match res {
Poll::Pending => Poll::Pending,
Poll::Ready(Err(_err)) => Poll::Ready(Err(anyhow!("gossip actor dropped"))),
Expand Down
2 changes: 1 addition & 1 deletion src/net/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<T> Timers<T> {
sleep.await;
self.map.drain_until(instant)
}
None => futures::future::pending().await,
None => std::future::pending().await,
}
}
}

0 comments on commit 9f5ef8f

Please sign in to comment.