mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-31 00:41:59 +00:00
feat(swarm): Make executor for connection tasks explicit (#3097)
Previously, the executor for connection tasks silently defaulted to a `futures::executor::ThreadPool`. This causes issues such as https://github.com/libp2p/rust-libp2p/issues/2230. With this patch, we force the user to choose, which executor they want to run the connection tasks on which results in overall simpler API with less footguns. Closes #3068.
This commit is contained in:
@@ -4,8 +4,11 @@
|
||||
|
||||
- Hide `prost::Error` from public API in `FromEnvelopeError::InvalidPeerRecord` and `signed_envelope::DecodingError`. See [PR 3058].
|
||||
|
||||
- Move `Executor` to `libp2p-swarm`. See [PR 3097].
|
||||
|
||||
[PR 3031]: https://github.com/libp2p/rust-libp2p/pull/3031
|
||||
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058
|
||||
[PR 3097]: https://github.com/libp2p/rust-libp2p/pull/3097
|
||||
|
||||
# 0.37.0
|
||||
|
||||
|
@@ -83,23 +83,3 @@ pub use upgrade::{InboundUpgrade, OutboundUpgrade, ProtocolName, UpgradeError, U
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
#[error(transparent)]
|
||||
pub struct DecodeError(prost::DecodeError);
|
||||
|
||||
use std::{future::Future, pin::Pin};
|
||||
|
||||
/// Implemented on objects that can run a `Future` in the background.
|
||||
///
|
||||
/// > **Note**: While it may be tempting to implement this trait on types such as
|
||||
/// > [`futures::stream::FuturesUnordered`], please note that passing an `Executor` is
|
||||
/// > optional, and that `FuturesUnordered` (or a similar struct) will automatically
|
||||
/// > be used as fallback by libp2p. The `Executor` trait should therefore only be
|
||||
/// > about running `Future`s in the background.
|
||||
pub trait Executor {
|
||||
/// Run the given future in the background until it ends.
|
||||
fn exec(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>);
|
||||
}
|
||||
|
||||
impl<F: Fn(Pin<Box<dyn Future<Output = ()> + Send>>)> Executor for F {
|
||||
fn exec(&self, f: Pin<Box<dyn Future<Output = ()> + Send>>) {
|
||||
self(f)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user