Remaining lifetime changes required by ibid.

This commit is contained in:
Jedrzej Stuczynski
2020-02-25 16:04:28 +00:00
parent d77f2b20ce
commit 87bbe9c864
3 changed files with 12 additions and 11 deletions
@@ -10,26 +10,26 @@ use std::time::Duration;
mod reconnector;
mod writer;
enum ConnectionState {
enum ConnectionState<'a> {
Writing(ConnectionWriter),
Reconnecting(ConnectionReconnector),
Reconnecting(ConnectionReconnector<'a>),
}
pub(crate) struct ConnectionManager {
pub(crate) struct ConnectionManager<'a> {
address: SocketAddr,
maximum_reconnection_backoff: Duration,
reconnection_backoff: Duration,
state: ConnectionState,
state: ConnectionState<'a>,
}
impl ConnectionManager {
impl<'a> ConnectionManager<'a> {
pub(crate) async fn new(
address: SocketAddr,
reconnection_backoff: Duration,
maximum_reconnection_backoff: Duration,
) -> Self {
) -> ConnectionManager<'a> {
// based on initial connection we will either have a writer or a reconnector
let state = match tokio::net::TcpStream::connect(address).await {
Ok(conn) => ConnectionState::Writing(ConnectionWriter::new(conn)),
@@ -1,4 +1,5 @@
use futures::future::LocalBoxFuture;
use futures::FutureExt;
use log::*;
use std::future::Future;
use std::io;
@@ -24,7 +25,7 @@ impl<'a> ConnectionReconnector<'a> {
address: SocketAddr,
reconnection_backoff: Duration,
maximum_reconnection_backoff: Duration,
) -> Self {
) -> ConnectionReconnector<'a> {
ConnectionReconnector {
address,
connection: tokio::net::TcpStream::connect(address).boxed_local(),
+4 -4
View File
@@ -29,12 +29,12 @@ impl Config {
}
}
pub struct Client {
connections_managers: HashMap<SocketAddr, ConnectionManager>,
pub struct Client<'a> {
connections_managers: HashMap<SocketAddr, ConnectionManager<'a>>,
}
impl Client {
pub async fn new(config: Config) -> Client {
impl<'a> Client<'a> {
pub async fn new(config: Config) -> Client<'a> {
let mut connections_managers = HashMap::new();
for endpoint in config.initial_endpoints {
connections_managers.insert(